10 for Pn=1 to 999999
11 Nxprm=nxtprm(Nxprm)
15 if Nxprm=Prv then stop
16 if fnPalin(Nxprm) then
17 :Sum=Sum-Ppp+Nxprm
20 :Ppp=Pp:Pp=P:P=Nxprm
40 :if fnPalin(Sum) then
50 :print Ppp;Pp;P,Sum;:if prmdiv(Sum)=Sum then print "*":else print
55 Prv=Nxprm
60 next Pn:print Nxprm
800 end
900 '
1000 fnPalin(N)
1010 T=1:S=cutspc(str(N))
1020 for I=1 to int(len(S)/2)
1030 if mid(S,I,1)<>mid(S,len(S)+1-I,1) then T=0
1040 next
1050 return(T)
The first two lines of the below output are spurious due to the methodology used in the program. The remaining lines show the three successive palindromic primes, and the sum. If the sum is also prime and asterisk (*) appears to the right of the line, as in the example, though the rules do not specifiy that primality is needed in the sum.
0 0 2 2 *
0 2 3 5 *
101 131 151 383 *
30103 30203 30403 90709 *
31013 31513 32323 94849 *
1120211 1123211 1126211 3369633
1221221 1235321 1242421 3698963 *
1300031 1303031 1311131 3914193
15485857
The final, single, number shows the highest prime tested, the 999,999th prime.
|
Posted by Charlie
on 2013-12-27 12:41:32 |