(Python)
def a(n):
m = 0
while m*(m+1)*(m+2)//6 <= n: m += 1
k, r, j = m + 4, n - m*(m+1)*(m+2)//6, 0
while r >= 0: r -= (m+1-j); j += 1
j += 1
return 2**k - 2**(k-j) - 2**(-r) - 1
(Python) # faster version for generating initial segment of sequence
from itertools import combinations, count, islice
def agen():
for d in count(4):
b, c = 2**d - 1, 2**(d-1)
for i, j in combinations(range(1, d-1), 2):
yield b - (c >> i) - (c >> j)
(Python)
from math import comb, isqrt
from sympy import integer_nthroot
a = (m:=integer_nthroot(6*n, 3)[0])+(n>comb(m+2, 3))+3
b = isqrt((j:=comb(a-1, 3)-n+1)<<3)+3>>1
c = j-comb((r:=isqrt(w:=j<<1))+(w>r*(r+1)), 2)
return (1<<a)-(1<<b)-(1<<c)-1 #
Chai Wah Wu, Dec 17 2024
(PARI) isok(k) = (k%2) && (#binary(k) == hammingweight(k)+2); \\
Michel Marcus, Oct 13 2022
(PARI) list(lim)=my(v=List()); for(n=4, logint(lim\=1, 2)+1, my(N=2^n-1); forstep(a=n-2, 2, -1, my(A=N-1<<a); forstep(b=a-1, 1, -1, my(t=A-1<<b); if(t>lim, break(2)); listput(v, t)))); Vec(v) \\
Charles R Greathouse IV, Oct 21 2022