OFFSET
0,4
FORMULA
EXAMPLE
+---+-----+---+---+---+---+------------+
| n | bin.|1's|sum|0's|sum| a(n) |
+---+-----+---+---+---+---+------------+
| 0 | 0 | 0 | 0 | 1 | 1 | 0 - 1 =-1 |
| 1 | 1 | 1 | 1 | 0 | 1 | 1 - 1 = 0 |
| 2 | 10 | 1 | 2 | 1 | 2 | 2 - 2 = 0 |
| 3 | 11 | 2 | 4 | 0 | 2 | 4 - 2 = 2 |
| 4 | 100 | 1 | 5 | 2 | 4 | 5 - 4 = 1 |
| 5 | 101 | 2 | 7 | 1 | 5 | 7 - 5 = 2 |
| 6 | 110 | 2 | 9 | 1 | 6 | 9 - 6 = 3 |
+---+-----+---+---+---+---+------------+
bin. - n written in base 2;
1's - number of 1's in binary expansion of n;
0's - number of 0's in binary expansion of n;
sum - total number of 1's (or 0's) in binary expansions of 0, ..., n.
MATHEMATICA
Accumulate[DigitCount[Range[0, 75], 2, 1] - DigitCount[Range[0, 75], 2, 0]]
PROG
(Python)
def A301336(n):
return sum(2*bin(i).count('1')-len(bin(i))+2 for i in range(n+1)) # Chai Wah Wu, Sep 03 2020
CROSSREFS
KEYWORD
sign,base
AUTHOR
Ilya Gutkovskiy, Mar 28 2018
STATUS
approved