login
a(n) is the number of prime palindromes with 2n+1 digits.
2

%I #30 Apr 15 2021 22:56:31

%S 4,15,93,668,5172,42042,353701,3036643,27045226,239093865,2158090933,

%T 19742800564

%N a(n) is the number of prime palindromes with 2n+1 digits.

%H Shyam Sunder Gupta, <a href="https://listserv.nodak.edu/cgi-bin/wa.exe?A2=NMBRTHRY;d9a588c5.0602">Palindromic Primes up to 10^19</a>.

%H Shyam Sunder Gupta, <a href="https://listserv.nodak.edu/cgi-bin/wa.exe?A2=NMBRTHRY;bdeb9ea2.0903">Palindromic Primes up to 10^21</a>.

%H Shyam Sunder Gupta, <a href="https://listserv.nodak.edu/cgi-bin/wa.exe?A2=NMBRTHRY;b79493a6.1310">Palindromic Primes up to 10^23</a>.

%e a(1)=15 because Number of prime palindromes with 3 digits is 15. [_Shyam Sunder Gupta_, Mar 14 2009]

%o (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

%o (Python)

%o from sympy import isprime

%o from itertools import product

%o def candidate_pals(n): # of length 2n + 1

%o if n == 0: yield from [2, 3, 5, 7]; return # one-digit primes

%o for rightbutend in product("0123456789", repeat=n-1):

%o rightbutend = "".join(rightbutend)

%o for end in "1379": # multi-digit primes must end in 1, 3, 7, or 9

%o left = end + rightbutend[::-1]

%o for mid in "0123456789": yield int(left + mid + rightbutend + end)

%o def a(n): return sum(isprime(p) for p in candidate_pals(n))

%o print([a(n) for n in range(6)]) # _Michael S. Branicky_, Apr 15 2021

%Y Subsequence of A016115, which is the main entry.

%K nonn,hard,base,more

%O 0,1

%A _Patrick De Geest_

%E a(9) from _Shyam Sunder Gupta_, Feb 12 2006

%E a(10) from _Shyam Sunder Gupta_, Mar 14 2009

%E a(11) from _Shyam Sunder Gupta_, Oct 05 2013