OFFSET
1,1
COMMENTS
On removing the leading digit, any subsequent leading zeros are also removed.
The sequence is finite, the final term being a(205696) = 1200000000413309, after which all digit removals or additions to 1200000000413309 lead to composites or primes that already appear in the sequence.
The largest term is a(175658) = 100000000000000000002000005325000035030170417366031.
The list of missing primes begins 5, 29, 53, 59, 83, 89, 223, 227, 229, ... .
See A389824 for the sequence starting at 1.
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..10000
Scott R. Shannon, Complete list of 205K terms
EXAMPLE
a(5) = 103 as a(4) = 13, and the primes created from removing a single digit from 13 are 3, which has been used, while the primes created from adding a single digit to 13 are 113, 313, 613, 103, 163, 173, 193, 131, 133, 137, 139. Of those 103 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 = 2, {2}
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,base,full
AUTHOR
Scott R. Shannon, Oct 16 2025
STATUS
approved
