OFFSET
0,1
LINKS
Shyam Sunder Gupta, Palindromic Primes up to 10^19.
Shyam Sunder Gupta, Palindromic Primes up to 10^21.
Shyam Sunder Gupta, Palindromic Primes up to 10^23.
EXAMPLE
a(1)=15 because Number of prime palindromes with 3 digits is 15. [Shyam Sunder Gupta, Mar 14 2009]
PROG
(PARI) a(n) = {my(nb = 0); forprime(p=10^(2*n), 10^(2*n+1)-1, if (eval(concat(Vecrev(Str(p)))) == p, nb++); ); nb; } \\ Michel Marcus, Jul 24 2015
(Python)
from sympy import isprime
from itertools import product
def candidate_pals(n): # of length 2n + 1
if n == 0: yield from [2, 3, 5, 7]; return # one-digit primes
for rightbutend in product("0123456789", repeat=n-1):
rightbutend = "".join(rightbutend)
for end in "1379": # multi-digit primes must end in 1, 3, 7, or 9
left = end + rightbutend[::-1]
for mid in "0123456789": yield int(left + mid + rightbutend + end)
def a(n): return sum(isprime(p) for p in candidate_pals(n))
print([a(n) for n in range(6)]) # Michael S. Branicky, Apr 15 2021
CROSSREFS
KEYWORD
nonn,hard,base,more
AUTHOR
EXTENSIONS
a(9) from Shyam Sunder Gupta, Feb 12 2006
a(10) from Shyam Sunder Gupta, Mar 14 2009
a(11) from Shyam Sunder Gupta, Oct 05 2013
STATUS
approved