OFFSET
1,2
COMMENTS
Leading 0's in binary expansions are ignored.
LINKS
EXAMPLE
PROG
(PARI) a(n) = { my (b=binary(n)); vecsum(setbinop((i, j) -> my (s=fromdigits(b[i..j], 2)); if (b[i], s, 2^(j-i+1)-1-s), [1..#b])) }
(Python)
def a(n):
N = n.bit_length()
c, s = ((1<<N)-1)^n, set()
for i in range(N):
for l in range(N-i):
mask = ((2<<l)-1) << i
s.add((mask&n) >> i)
s.add((mask&c) >> i)
return sum(s)
print([a(n) for n in range(1, 60)]) # Michael S. Branicky, Jul 28 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Jul 28 2022
STATUS
approved