OFFSET
1,1
EXAMPLE
2, 3, 5, 7, 11, 101, 131, 151, 181, 191, 313, 353, 373, 383, 727 and 757 are the first sixteen palindromic primes.
MATHEMATICA
NextPalindrome[n_] := Block[ {lg = Floor@ Log[10, n] + 1, idn = IntegerDigits@ n}, If[ Union@ idn == {9}, Return[n + 2], If[lg < 2, Return[n + 1], If[ FromDigits@ Reverse@ Take[ idn, Ceiling[lg/2]] > FromDigits@ Take[ idn, -Ceiling[lg/2]], FromDigits@ Join[ Take[ idn, Ceiling[lg/2]], Reverse@ Take[ idn, Floor[lg/2]]], idfhn = FromDigits@ Take[ idn, Ceiling[lg/2]] + 1; idp = FromDigits@ Join[ IntegerDigits@ idfhn, Drop[ Reverse@ IntegerDigits@ idfhn, Mod[lg, 2]]] ]]]];
c = 0; pal = 0; Do[ While[c < 2^n, pal = NextPalindrome@ pal; If[ PrimeQ@ pal, c++ ]]; Print@ pal, {n, 0, 20}]
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Robert G. Wilson v, Feb 04 2005, corrected Nov 16 2006
STATUS
approved