OFFSET
0,4
LINKS
MATHEMATICA
Table[#.Reverse@ Range@ Length@ # &@ IntegerDigits[n, 2] - DigitCount[2 n - DigitCount[2 n, 2, 1], 2, 1], {n, 0, 120}] (* Michael De Vlieger, Mar 20 2017, after Jean-François Alcover at A029931 *)
PROG
(PARI)
a(n) = if(n<1, 0, a(n - 2^logint(n, 2)) + logint(n, 2) + 1);
b(n) = if(n<1, 0, b(n\2) + n%2);
A(n) = b(2*n - b(2*n));
for(n=0, 150, print1(a(n) - A(n), ", ")) \\ Indranil Ghosh, Mar 21 2017
(Python)
import math
def L(n): return int(math.floor(math.log(n, 2)))
def a(n): return 0 if n<1 else a(n - 2**L(n)) + L(n) + 1
def A(n): return bin(2*n - bin(2*n)[2:].count("1"))[2:].count("1")
print([a(n) - A(n) for n in range(151)]) # Indranil Ghosh, Mar 21 2017
CROSSREFS
KEYWORD
AUTHOR
Antti Karttunen, Mar 19 2017
STATUS
approved