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
