%I #39 Apr 03 2023 10:36:09
%S 2,3,5,7,313,353,373,383,797,30103,31013,70607,73037,76367,79397,
%T 3002003,7096907,7693967,700090007,799636997,70060906007,
%U 3000002000003,7030000000307,300000020000003,300001030100003,310000060000013,38000000000000000000083,30000000004000300040000000003,3000001000000000000000000000001000003
%N Every suffix of palindromic prime a(n) is prime (left-truncatable).
%H I. O. Angell and H. J. Godwin, <a href="http://dx.doi.org/10.1090/S0025-5718-1977-0427213-2">On Truncatable Primes</a>, Math. Comput. 31, 265-267, 1977.
%H C. K. Caldwell, <a href="https://t5k.org/glossary/page.php?sort=LeftTruncatablePrime">Left</a> and <a href="https://t5k.org/glossary/page.php?sort=RightTruncatablePrime">Right</a> truncatable primes.
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/PrimeString.html">Prime strings</a>
%H <a href="/index/Tri#tprime">Index entries for sequences related to truncatable primes</a>
%t d[n_]:=IntegerDigits[n]; ltrQ[n_]:=And@@PrimeQ[NestWhileList[FromDigits[Drop[d[#],1]]&,n,#>9&]]; palQ[n_]:=Reverse[x=d[n]]==x; Select[Prime[Range[550000]],palQ[#]&<rQ[#]&] (* _Jayanta Basu_, Jun 02 2013 *)
%o (Python)
%o from sympy import isprime
%o from itertools import count, islice
%o def agen(verbose=False):
%o prime_strings, alst = {"3", "7"}, []
%o yield from [2, 3, 5, 7]
%o for digs in count(2):
%o new_prime_strings = set()
%o for p in prime_strings:
%o for d in "123456789":
%o ts = d + "0"*(digs-1-len(p)) + p
%o if isprime(int(ts)):
%o new_prime_strings.add(ts)
%o prime_strings |= new_prime_strings
%o pals = [int(s) for s in new_prime_strings if s == s[::-1]]
%o yield from sorted(pals)
%o if verbose: print("...", digs, len(prime_strings), time()-time0)
%o print(list(islice(agen(), 20))) # _Michael S. Branicky_, Apr 04 2022
%Y Cf. A002385, A033664, A024785, A032437, A020994, A024770, A052023, A052025, A050986, A050987.
%K nonn,base
%O 1,1
%A _G. L. Honaker, Jr._ and _Patrick De Geest_, Nov 15 1999
%E Inserted missing 31013 by _Jayanta Basu_, Jun 02 2013
%E a(27)-a(29) from _Michael S. Branicky_, Apr 04 2022
|