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, 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
Examples
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.
Links
- David A. Corneth, Table of n, a(n) for n = 1..10011
Programs
-
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 *)
-
PARI
upto(n) = { my(res = List()); for(i = 0, logint(n, 2)+1, pow2 = 1<
-
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<
>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
Comments