login
A389825
a(1) = 2; for n > 1, a(n) is the smallest unused prime number that can be created by either removing or adding a single digit anywhere in the value of a(n-1).
7
2, 23, 3, 13, 103, 1013, 101, 11, 113, 1103, 10103, 100103, 1001003, 100003, 1000003, 10000103, 100001053, 10001053, 100010353, 1000103453, 100103453, 10103453, 1010353, 10101353, 1001353, 100153, 1001153, 1153, 11353, 113153, 1013153, 10123153, 101231353, 1010231353
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
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
Cf. A389824 (start at 1), A000040, A080603, A080608, A068166.
Sequence in context: A383790 A107801 A262702 * A360534 A076653 A114008
KEYWORD
nonn,fini,base,full
AUTHOR
Scott R. Shannon, Oct 16 2025
STATUS
approved