login
A384021
Powers of 2 along with numbers one power of 2 less than binary repunits, but the power of two subtracted does not flip the leading bit.
1
1, 2, 4, 5, 6, 8, 11, 13, 14, 16, 23, 27, 29, 30, 32, 47, 55, 59, 61, 62, 64, 95, 111, 119, 123, 125, 126, 128, 191, 223, 239, 247, 251, 253, 254, 256, 383, 447, 479, 495, 503, 507, 509, 510, 512, 767, 895, 959, 991, 1007, 1015, 1019, 1021, 1022, 1024, 1535, 1791, 1919
OFFSET
1,2
COMMENTS
Also numbers where in the binary expansion the bit 0 or 1 occurs exactly once.
Union of A000079 and A164874. - Chai Wah Wu, May 21 2025
LINKS
EXAMPLE
4 = 2^2 is term as it is a power of 2.
5 is a term as 5 = (2^3 - 1) - 2^1; a power of two less than a binary repunit and subtracting 2 from 7 does not flip the most significant bit of 7.
MATHEMATICA
A384021list[k_] := Flatten[{1, Table[{2^i - 1 - BitShiftRight[2^i, Range[2, i]], 2^i}, {i, 2 - Boole[k == 1], k}]}]; (* returns terms up to 2^k *)
A384021list[11] (* Paolo Xausa, Jun 12 2025 *)
PROG
(PARI) upto(n) = {
my(res = List());
for(i = 0, logint(n, 2)+1,
pow2 = 1<<i;
listput(res, pow2);
for(j = 0, i-2,
listput(res, pow2 - 1<<j - 1);
);
);
Set(res)}
(Python)
from itertools import count, islice
def agen(): # generator of terms
yield from (1, 2)
for d in count(3):
m, b1 = 1<<(d-1), (1<<d) - 1
yield m
yield from (b1-(m>>i) for i in range(1, d))
print(list(islice(agen(), 58))) # Michael S. Branicky, May 18 2025
(Python)
def A384021(n):
def bisection(f, kmin=0, kmax=1):
while f(kmax) > kmax: kmax <<= 1
kmin = kmax >> 1
while kmax-kmin > 1:
kmid = kmax+kmin>>1
if f(kmid) <= kmid:
kmax = kmid
else:
kmin = kmid
return kmax
def f(x):
if x<=1: return n
l, s = x.bit_length(), bin(x)[2:]
if (m:=s.count('0'))>0: return n+x-s.index('0')+(m>1)-(l*(l-1)>>1)
return n+x+1-(l*(l+1)>>1)
return bisection(f, n, n) # Chai Wah Wu, May 21 2025
CROSSREFS
Cf. A383666 (complement), A000079, A030130, A164874.
Sequence in context: A353187 A389395 A099247 * A192583 A240064 A007192
KEYWORD
nonn,base,easy
AUTHOR
David A. Corneth, May 17 2025
STATUS
approved