OFFSET
1,2
COMMENTS
On removing the leading digit, any subsequent leading zeros are also removed.
The sequence is finite, the final term being a(17608) = 10253452803799, after which all digit removals or additions to 10253452803799 lead to composites or primes that already appear in the sequence.
The largest term is a(9551) = 100000000000206050030346930504857.
The list of missing primes begins 7, 17, 19, 31, 37, 41, 43, 47, 61, ... .
See A389825 for the sequence starting at 2.
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..17608
EXAMPLE
a(10) = 229 as a(9) = 29, and the primes created from removing a single digit from 29 are 2, which has been used, while the primes created from adding a single digit to 29 are 229, 829, 929, 239, 269, 293. Of those 229 is the smallest and is therefore the next term chosen.
PROG
(Python)
from gmpy2 import is_prime
from itertools import islice
def agen(): # generator of terms
an, aset = 1, {1}
while an != -1:
yield an
aset.add(an)
s = str(an)
D = set(p for i in range(len(s)) if len(t:=s[:i]+s[i+1:]) and is_prime(p:=int(t)))
if D and (Dcands:=D-aset):
an = min(D - aset)
continue
A = set(p for i in range(len(s)+1) for d in "0123456789" if is_prime(p:=int(s[:i]+d+s[i:])))
an = min(Acands) if A and (Acands:=A-aset) else -1
print(f"Last term is a({len(aset)}).")
print(list(islice(agen(), 40))) # Michael S. Branicky, Oct 19 2025
CROSSREFS
KEYWORD
nonn,fini,full,base
AUTHOR
Scott R. Shannon, Oct 16 2025
STATUS
approved
