login
Palindromes that can be written in more than one way as the sum of two distinct palindromic primes.
1

%I #11 Sep 04 2022 12:46:38

%S 282,484,858,888,21912,22722,23832,24642,25752,26662,26762,26862,

%T 26962,27672,27772,27872,27972,28482,28782,28882,28982,29692,29792,

%U 29892,29992,40704,41514,41614,41814,42624,42824,42924,43434,43734,43834,43934,44744,44844,44944,45354

%N Palindromes that can be written in more than one way as the sum of two distinct palindromic primes.

%C This sequence doesn't contain any numbers with an even number of digits, see proof in A356824.

%C Subsequence of A356824.

%C All numbers in this sequence are even. Proof: any 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 term is the sum of two odd numbers.

%e 282 can be expressed as a sum of two distinct palindromic primes in two ways: 282 = 101 + 181 = 131 + 151. Thus, 282 is in this sequence.

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

%t Sort[Transpose[Select[Tally[Flatten[Table[q[[n]] + q[[m]], {n, Length[q]}, {m, n + 1, Length[q]}]]], PalindromeQ[#[[1]]] && #[[2]] > 1 &]][[1]]]

%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, once, twice = 10**dd, [], [2, 3, 5, 7, 11], set(), set()

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

%o sums = (p+q for p in pp for q in pp if p<q and p+q<N and ispal(p+q))

%o for s in sums:

%o if s in once: twice.add(s)

%o else: once.add(s)

%o return sorted(twice)

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

%Y Cf. A356824.

%K nonn,base

%O 1,1

%A _Tanya Khovanova_ and _Massimo Kofler_, Aug 31 2022