login
A085054
Smallest palindromic prime containing the n-th palindrome.
2
101, 11, 2, 3, 11411, 5, 10601, 7, 181, 191, 11, 72227, 13331, 1444441, 15551, 16661, 77377, 78887, 19991, 101, 1114111, 1212121, 131, 11411, 151, 1611161, 1117111, 181, 191, 1120211, 1212121, 72227, 32323, 12421, 3252523, 1126211, 12721, 12821
OFFSET
1,1
EXAMPLE
1311131 contains the palindrome 111.
MATHEMATICA
NextPalindrome[n_] := Block[ {l = Floor[ Log[ 10, n] + 1], idn = IntegerDigits[ n]}, If[ Union[ idn] == {9}, Return[n + 2], If[l < 2, Return[n + 1], If[ FromDigits[ Reverse[ Take[ idn, Ceiling[l/2]]]] FromDigits[ Take[ idn, -Ceiling[l/2]]], FromDigits[ Join[ Take[ idn, Ceiling[l/2]], Reverse[ Take[ idn, Floor[l/2]]]]],
idfhn = FromDigits[ Take[ idn, Ceiling[l/2]]] + 1; idp = FromDigits[ Join[ IntegerDigits[ idfhn], Drop[ Reverse[ IntegerDigits[ idfhn]], Mod[l, 2]]]] ]]]]; f[n_] := Block[{k = 0, s = ToString[n]}, While[ !PrimeQ[k] || FromDigits[ Reverse[ IntegerDigits[k]]] != k || StringPosition[ ToString[k], s] == {}, k++ ]; k]; Map[f, NestList[ NextPalindrome, 0, 40]]
PROG
(Python)
from itertools import count
from sympy import isprime
def A085054(n):
s = str((c:=n-x)*x+int(str(c)[-2::-1] or 0) if n<(x:=10**(len(str(n>>1))-1))+(y:=10*x) else (c:=n-y)*y+int(str(c)[::-1] or 0))
for k in count(n):
p = (c:=k-x)*x+int(str(c)[-2::-1] or 0) if k<(x:=10**(len(str(k>>1))-1))+(y:=10*x) else (c:=k-y)*y+int(str(c)[::-1] or 0)
if s in str(p) and isprime(p):
return p # Chai Wah Wu, Jul 11 2024
CROSSREFS
Sequence in context: A341634 A060386 A062584 * A084045 A085419 A083982
KEYWORD
base,nonn
AUTHOR
Amarnath Murthy and Meenakshi Srikanth (menakan_s(AT)yahoo.com), Jun 26 2003
EXTENSIONS
Edited, corrected and extended by Robert G. Wilson v, Jun 28 2003
STATUS
approved