|
|
A016115
|
|
Number of prime palindromes with n digits.
|
|
6
|
|
|
4, 1, 15, 0, 93, 0, 668, 0, 5172, 0, 42042, 0, 353701, 0, 3036643, 0, 27045226, 0, 239093865, 0, 2158090933, 0, 19742800564, 0
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,1
|
|
COMMENTS
|
Every palindrome with an even number of digits is divisible by 11 and therefore is composite (not prime). Hence there is only one palindromic prime with an even number of digits, namely 11 itself. - Martin Renner, Apr 15 2006
|
|
LINKS
|
Cécile Dartyge, Bruno Martin, Joël Rivat, Igor E. Shparlinski, and Cathy Swaenepoel, Reversible primes, arXiv:2309.11380 [math.NT], 2023. See p. 36.
|
|
FORMULA
|
|
|
MAPLE
|
# A016115 Gets numbers of base-10 palindromic primes with exactly d digits, 1 <= d <= 13 (say), in the list "lis"
lis:=[4, 1];
for d from 3 to 13 do
if d::even then
lis:=[op(lis), 0];
else
m:= (d-1)/2:
Res2 := [seq(seq(n*10^(m+1)+y*10^m+digrev(n), y=0..9), n=10^(m-1)..10^m-1)]:
ct:=0; for x in Res2 do if isprime(x) then ct:=ct+1; fi: od:
lis:=[op(lis), ct];
fi:
lprint(d, lis);
od:
|
|
MATHEMATICA
|
A016115[n_] := Module[{i}, If[EvenQ[n] && n > 2, Return[0]]; Return[Length[Select[Range[10^(n - 1), 10^n - 1], # == IntegerReverse[#] && PrimeQ[#] &]]]];
(* -OR- A less straightforward implementation, but more efficient in that the palindromes are constructed instead of testing every number in the range. *)
A016115[n_] := Module[{c, f, t0, t1},
If[n == 2, Return[1]];
If[EvenQ[n], Return[0]];
c = 0; t0 = 10^((n - 1)/2); t1 = t0*10;
For[f = t0, f < t1, f++,
If[n != 1 && MemberQ[{2, 4, 5, 6, 8}, Floor[f/t0]], f = f + t0 - 1; Continue[]];
If[PrimeQ[f*t0 + IntegerReverse[Floor[f/10]]], c++]]; Return[c]];
|
|
PROG
|
(Python)
from sympy import isprime
from itertools import product
def pals(d, base=10): # all d-digit palindromes
digits = "".join(str(i) for i in range(base))
for p in product(digits, repeat=d//2):
if d > 1 and p[0] == "0": continue
left = "".join(p); right = left[::-1]
for mid in [[""], digits][d%2]: yield int(left + mid + right)
def a(n): return int(n==2) if n%2 == 0 else sum(isprime(p) for p in pals(n))
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,hard,base,more
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|