login
Palindromes that can be written as the sum of two palindromic primes.
2

%I #17 Sep 04 2022 12:46:24

%S 4,5,6,7,8,9,22,202,232,252,262,282,292,414,444,454,464,474,484,494,

%T 626,666,686,696,808,828,858,878,888,898,20002,20602,20802,20902,

%U 21612,21712,21812,21912,22622,22722,22822,22922,23632,23732,23832,23932,24642,24742,24842,24942

%N Palindromes that can be written as the sum of two palindromic primes.

%C With the exception of 22, which is the sum of 11 and 11, no term of this sequence has an even number of digits. Proof: Other than 11, palindromes with an even number of digits are not primes (since they are divisible by 11). Suppose m is a term of this sequence with 2k digits. Then m must be the sum of two palindromic primes p and q with 2k-1 digits each. It follows that the first and the last digit of m is 1. Hence, either p or q is even, creating a contradiction with primality.

%C With the exception of 5, 7, and 9, all terms of this sequence are even. Proof: two consecutive multi-digit palindromes differ by at least 10, so larger palindromes can't be the sum of a palindromic prime and 2. Thus, each multi-digit term is the sum of two odd numbers.

%e 282 can be written as the sum of two prime palindromes, 101 and 181. Thus, 282 is in the sequence.

%t q := Select[Range[30000], PalindromeQ[#] && PrimeQ[#] &]

%t Select[Union[Flatten[Table[q[[n]] + q[[m]], {n, Length[q]}, {m, Length[q]}]]],

%t PalindromeQ[#] &]

%o (Python)

%o from sympy import isprime

%o from itertools import product

%o def ispal(n): s = str(n); return s == s[::-1]

%o def oddpals(d): # generator of odd palindromes with d digits

%o if d == 1: yield from [1, 3, 5, 7, 9]; return

%o for first in "13579":

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

%o left = "".join(p); right = left[::-1]

%o for mid in [[""], "0123456789"][d%2]:

%o yield int(first + left + mid + right + first)

%o def auptod(dd):

%o N, alst, pp = 10**dd, [], [2, 3, 5, 7, 11]

%o pp += [p for d in range(3, dd+1, 2) for p in oddpals(d) if isprime(p)]

%o return sorted(set(p+q for p in pp for q in pp if p+q<N and ispal(p+q)))

%o print(auptod(5)) # _Michael S. Branicky_, Aug 29 2022

%Y Cf. A002113, A002385, A261906.

%K nonn,base

%O 1,1

%A _Tanya Khovanova_, Aug 29 2022