login
A040025
a(n) is the number of prime palindromes with 2n+1 digits.
2
4, 15, 93, 668, 5172, 42042, 353701, 3036643, 27045226, 239093865, 2158090933, 19742800564, 180815391365
OFFSET
0,1
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
Subsequence of A016115, which is the main entry.
Sequence in context: A372730 A332533 A013193 * A366697 A208991 A109365
KEYWORD
nonn,hard,base,more
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
a(12) from Shyam Sunder Gupta, Dec 19 2024
STATUS
approved