login
a(n) is the least prime whose representation contains a palindromic substring of length n.
1

%I #10 Feb 12 2021 08:20:20

%S 2,11,101,11113,10301,1011013,1003001,100110013,100030001,10000000019,

%T 10000500001,1000011000017,1000008000001,100000440000011,

%U 100000323000001,10000001100000011,10000000500000001,1000000011000000019,1000000008000000001,100000000660000000013

%N a(n) is the least prime whose representation contains a palindromic substring of length n.

%H Michael S. Branicky, <a href="/A115941/b115941.txt">Table of n, a(n) for n = 1..25</a>

%e a(6)=1011013 since it is the least prime that contains a palindromic substring (101101) of length 6.

%o (Python)

%o from sympy import isprime

%o from itertools import product

%o def pals_to_test(n, odd=True):

%o if n <= 2: yield [2, 11][n-1]

%o if odd: ruled_out = "024568" # can't be even or multiple of 5

%o else: ruled_out = "0"

%o midrange = [[""], [str(i) for i in range(10)]]

%o for p in product("0123456789", repeat=n//2):

%o left = "".join(p)

%o if len(left):

%o if left[0] in ruled_out: continue

%o for middle in midrange[n%2]:

%o out = left+middle+left[::-1]

%o if odd: yield out

%o else:

%o for last in "1379": yield out+last

%o def a(n):

%o palsgen = pals_to_test(n, n%2 == 1)

%o while True:

%o strpal = next(palsgen)

%o pal = int(strpal)

%o if isprime(pal): return pal

%o print([a(n) for n in range(1, 18)]) # _Michael S. Branicky_, Feb 11 2021

%Y Cf. A056732.

%K nonn,base

%O 1,1

%A _Giovanni Resta_, Feb 06 2006

%E a(18) and beyond from _Michael S. Branicky_, Feb 11 2021