%I #39 May 13 2022 09:49:44
%S 2,11,101,1221221,112111211,121111121,144010441,335414533,12444144421,
%T 14244144241,15525152551,34254145243,1034450544301,1044141414401,
%U 1044531354401,1045341435401,1053441443501,1054341434501,1054431344501,1055050505501,1055150515501,1055500055501,1104440444011
%N Palindromic primes (palprimes) whose sum of factorials of digits is also a palprime.
%C a(n) has an odd number of digits with the middle digit is 0 or 1 except for the terms 2 and 11. - _David A. Corneth_, May 05 2022
%D 1221221 is a term because 1!+2!+2!+1!+2!+2!+1! = 11.
%H Michael S. Branicky, <a href="/A351622/b351622.txt">Table of n, a(n) for n = 1..10000</a>
%o (PARI) forprime(i=1, 10^12, di=digits(i); if(di==Vecrev(di), s=sum(j=1,#di,di[j]!); ds=digits(s); if(isprime(s) && ds==Vecrev(ds), print1(i,", "))))
%o (Python)
%o from math import factorial
%o from sympy import isprime
%o from itertools import count, islice, product
%o myfact = {d:factorial(int(d)) for d in "0123456789"}
%o def ispal(s): return s == s[::-1]
%o def sofod(s): return sum(myfact[d] for d in s)
%o def palprimecandstrs():
%o yield from ["2", "3", "5", "7", "11"]
%o for digs in count(3, step=2):
%o for last in "1379":
%o for p in product("0123456789", repeat=digs//2-1):
%o left = "".join(p)
%o for mid in "01": # else sofod even (cf. Corneth comment)
%o yield last + left + mid + left[::-1] + last
%o def agen(): # generator of terms
%o for strp in palprimecandstrs():
%o s = sofod(strp)
%o if ispal(str(s)) and isprime(s):
%o p = int(strp)
%o if isprime(p):
%o yield p
%o print(list(islice(agen(), 23))) # _Michael S. Branicky_, May 13 2022
%Y Subsequence of A002385.
%Y Cf. A061602.
%K nonn,base
%O 1,1
%A _Alexandru Petrescu_, May 05 2022
%E More terms from _David A. Corneth_, May 06 2022
|