login
A389925
a(1) = 1; for n > 1, a(n) is the smallest unused prime number, when read in binary, that can be created by either removing or adding a single 0 or 1 anywhere in the binary value of a(n-1).
3
1, 2, 5, 3, 7, 11, 19, 37, 17, 41, 73, 137, 277, 139, 67, 131, 263, 523, 1051, 2099, 1049, 521, 257, 577, 1153, 641, 1283, 643, 1291, 647, 1303, 2647, 599, 311, 151, 23, 43, 83, 163, 331, 167, 71, 199, 103
OFFSET
1,2
COMMENTS
The binary version of A389824.
The sequence is finite, the last term being a(44) = 103, after which all removals or additions of a single 0 or 1 to the binary value of 103 = 1100111_2 lead to composites or primes, when read in binary, that already appear in the sequence.
EXAMPLE
a(8) = 37 = 100101_2 as a(7) = 19 = 10011_2, and the primes created from removing a single 0 or 1 from 10011_2 are 3 = 11_2 and 11 = 1011_2, both of which have already been used, while the primes created from adding a single 0 or 1 to 10011_2 are 37 = 100101_2 and 43 = 101011_2. Of those 37 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)
b = bin(an)[2:]
D = set(p for i in range(len(b)) if len(t:=b[:i]+b[i+1:]) and is_prime(p:=int(t, 2)))
if D and (Dcands:=D-aset):
an = min(D - aset)
continue
A = set(p for i in range(len(b)+1) for d in "01" if is_prime(p:=int(b[:i]+d+b[i:], 2)))
an = min(Acands) if A and (Acands:=A-aset) else -1
print(f"Last term is a({len(aset)}).")
print(list(islice(agen(), 45))) # Michael S. Branicky, Oct 21 2025
CROSSREFS
KEYWORD
nonn,fini,full,base
AUTHOR
Scott R. Shannon, Oct 19 2025
STATUS
approved