'Subject: The strong Goldbach conjecture:
'         every even integer greater than 2 is the sum of two primes.
'Author : Sjoerd.J.Schaper
'Date   : 08-05-2005
'Code   : QuickBasic, PDS, VBdos
REM $LANG: "qb"
REM $INCLUDE: 'largeint.bi'
CONST a = 0, d = 1, p = 2, v = 3
r = LargeInit(v, "goldbach")
CONST fl = -1 '                       first pair only-flag
CLS : tim# = TIMER: lin = 7

cx = PrimCeil
IF cx = 0 THEN
   Prints "primelist is empty - first run PrimFlgs.bas", 2
   GOTO eind
END IF

begin:
LOCATE 1, 1
PRINT "   +-------------------------+"
PRINT "   |  input a to partition,  |"
PRINT "   |  0 to exit.             |"
PRINT "   |                         |"
PRINT "   +-------------------------+"
LOCATE 4, 7: INPUT ; "a"; g$
IF INSTR(g$, "'") THEN GOTO begin
IF VAL(g$) < 3 THEN GOTO eind

LOCATE lin, 1
Readst a, g$
Printn a, "a = ", "", 1

IF Mp2(a, 2) = 0 THEN '               even numbers
   sw = 0: DO
      cf = Nxtprm(sw) '               next small prime p
      IF cf > cx THEN
         Prints "out of primes", 1: EXIT DO
      END IF
      Letf p, cf
      Dup a, d: Subt d, p
      IF Cmp(p, d) = 1 THEN EXIT DO ' p > a / 2
      IF IsPPrm(d, v, 5) THEN '       test a - p
         Printn p, "  = ", "", 0
         Printn d, " + ", "", 1
         IF fl THEN EXIT DO
      END IF
   LOOP
ELSE
   Prints "odd argument", 1
END IF
Prints "", 1
lin = CSRLIN
GOTO begin

eind:
LOCATE lin, 1
g$ = STR$(CSNG(TIMER - tim#))
Prints "Timer:" + g$ + " s", 1
CALL Term
SYSTEM

