A032937 Numbers k whose base-2 representation Sum_{i=0..m} d(i)*2^(m-i) has d(i)=0 for all odd i, excluding 0. Here m is the position of the leading bit of k.
1, 2, 4, 5, 8, 10, 16, 17, 20, 21, 32, 34, 40, 42, 64, 65, 68, 69, 80, 81, 84, 85, 128, 130, 136, 138, 160, 162, 168, 170, 256, 257, 260, 261, 272, 273, 276, 277, 320, 321, 324, 325, 336, 337, 340, 341, 512, 514, 520, 522, 544, 546
Offset: 1
Programs
-
Mathematica
Join[{1},Select[Range[0,600],Union[Take[IntegerDigits[#,2],{2,-1,2}]]=={0}&]] (* Harvey P. Dale, Sep 17 2023 *)
-
Python
from gmpy2 import digits def A032937(n): def bisection(f,kmin=0,kmax=1): while f(kmax) > kmax: kmax <<= 1 while kmax-kmin > 1: kmid = kmax+kmin>>1 if f(kmid) <= kmid: kmax = kmid else: kmin = kmid return kmax def g(x): s = digits(x,4) for i in range(l:=len(s)): if s[i]>'1': break else: return int(s,2) return int(s[:i]+'1'*(l-i),2) def f(x): return n+x-g(x)-g(x>>1) return bisection(f,n,n) # Chai Wah Wu, Oct 29 2024
Comments