|
PROG
|
(PARI) nextpalprime(n) = my(p=nextprime(n)); while(p!=eval(concat(Vecrev(Str(p)))), p=nextprime(p+1)); p
terms(n) = my(i=0, k=1, s="", p=10); while(i < n, p=nextpalprime(p+1); s=Str(s, p); if(ispseudoprime(eval(s)), print1(k, ", "); i++); k++)
terms(3) \\ print initial three terms
(Python)
from sympy import isprime, nextprime
def ispal(n): strn = str(n); return strn == strn[::-1]
def agen():
np, p, pstr = 1, 11, "11"
while True:
if isprime(int(pstr)): yield np
p = nextprime(p)
while not ispal(p): p = nextprime(p)
np += 1
pstr += str(p)
|