5 open "superprm.txt" for output as #2
10 while 1=1
20 P=nxtprm(P)
30 print #2,prm(P)
35 Ct=Ct+1
40 wend
finds 1464 superprimes, the largest being 131071 (the 12,251st prime), before reaching UBASIC's limit as to the numeration of primes. UBASIC can't hold all these numbers in an array as it's limited to 200 variables, including array members, so the next part is done in QuickBasic.
The QuickBasic program reads the generated list to find arithmetic progressions and remember the one with the smallest high number:
DECLARE FUNCTION isSP! (x!)
DIM SHARED l
DIM SHARED ct
OPEN "superprm.txt" FOR INPUT AS #1
DO
INPUT #1, p
ct = ct + 1
LOOP UNTIL EOF(1)
CLOSE 1
DIM SHARED sp(ct)
OPEN "superprm.txt" FOR INPUT AS #1
ct = 0
DO
INPUT #1, p
ct = ct + 1
sp(ct) = p
LOOP UNTIL EOF(1)
CLOSE 1
minim = 9999999
FOR i = 1 TO ct - 3
FOR j = i + 1 TO ct - 2
l = j
a = sp(i): b = sp(j)
incr = b - a
c = b + incr: d = c + incr
IF isSP(c) THEN
IF isSP(d) THEN
PRINT a; b; c; d
IF d < minim THEN
savea = a: saveb = b: savec = c: minim = d
END IF
END IF
END IF
NEXT
NEXT
PRINT savea; saveb; savec; minim
FUNCTION isSP (x)
low = j + 1: high = ct
DO
middle = INT((high + low) / 2)
IF sp(middle) > x THEN high = middle - 1
IF sp(middle) < x THEN low = middle + 1
IF sp(middle) = x THEN EXIT DO
LOOP UNTIL low >= high
middle = INT((high + low) / 2)
IF sp(middle) = x THEN isSP = -1: ELSE isSP = 0
END FUNCTION
It finds the series with the lowest value of Z (d in my program) is
353 431 509 587
We can verify that these are in fact superprimes from:
10 for I=1 to 9999
20 P=prm(I)
30 if P=353 or P=431 or P=509 or P=587 then print I,P
40 next
which lists which primes these are, and they are all in fact Pth primes where P is also prime:
P superprime
in sequence
71 353
83 431
97 509
107 587
and of course the difference between successive values is the same: 78.
|
Posted by Charlie
on 2011-07-18 17:48:43 |