OFFSET
1,2
COMMENTS
The longest run of zeros in all binary expansions from 1 to k will belong to the largest power of 2 less than or equal to k, if it exists. The run will be of length m_max = floor(log_2(k)), and exactly one run of length m_max will exist for any k > 1.
Inclusion in this sequence is a prerequisite for forming a palindrome from the binary expansions of 1 to k, described in A291633.
EXAMPLE
k=1 is a term since 1..k in binary is 1 alone which has no zero runs, therefore all numbers of runs are even.
k=2 is a term since 1..k in binary is 1.10 which is 1 run of 1 zero which is length m_max = floor(log_2(k)) = 1.
k=3: 1.10.11 # 1 run of 1, m_max = 1
k=5: 1.10.11.100.101 # 2 runs of 1, 1 run of 2, m_max = 2
k=11: 1.10.11.100.101.110.111.1000.1001.1010.1011
which is 6 of 1, 2 of 2, 1 of 3, m_max = 3
k=20: 1.10.11.100.101.110.111.1000.1001.1010.1011.1100.
1101.1110.1111.10000.10001.10010.10011.10100
which is 10 of 1, 6 of 2, 2 of 3, 1 of 4, m_max = 4
PROG
(Python)
from collections import Counter
from itertools import count, groupby, islice
def rlz(n): return [len(list(g)) for k, g in groupby(bin(n)[2:]) if k=="0"]
def agen(): # generator of terms
c = Counter()
for n in count(1):
c.update(r for r in rlz(n))
if all(c[m]&1 == 0 for m in c if m != max(c)):
yield n
print(list(islice(agen(), 50))) # Michael S. Branicky, Feb 04 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Tyler Busby, Feb 03 2023
STATUS
approved