OFFSET
0,3
LINKS
EXAMPLE
+---+-----+---+---+---+---+----------+
| n | bin.|0's|sum|1's|sum| a(n) |
+---+-----+---+---+---+---+----------+
| 0 | 0 | 1 | 1 | 0 | 0 | 1*0 = 0 |
| 1 | 1 | 0 | 1 | 1 | 1 | 1*1 = 1 |
| 2 | 10 | 1 | 2 | 1 | 2 | 2*2 = 4 |
| 3 | 11 | 0 | 2 | 2 | 4 | 2*4 = 8 |
| 4 | 100 | 2 | 4 | 1 | 5 | 4*5 = 20 |
| 5 | 101 | 1 | 5 | 2 | 7 | 5*7 = 35 |
| 6 | 110 | 1 | 6 | 2 | 9 | 6*9 = 54 |
+---+-----+---+---+---+---+----------+
bin. - n written in base 2;
0's - number of 0's in binary expansion of n;
1's - number of 1's in binary expansion of n;
sum - total number of 0's (or 1's) in binary expansions of 0, ..., n.
MAPLE
b:= proc(n) option remember; `if`(n=0, [1, 0], b(n-1)+
(l-> [add(1-i, i=l), add(i, i=l)])(Bits[Split](n)))
end:
a:= n-> (l-> l[1]*l[2])(b(n)):
seq(a(n), n=0..50); # Alois P. Heinz, Mar 01 2023
MATHEMATICA
Accumulate[DigitCount[Range[0, 50], 2, 0]] Accumulate[DigitCount[Range[0, 50], 2, 1]]
PROG
(Python)
def A301896(n): return (2+(n+1)*(m:=(n+1).bit_length())-(1<<m)-(k:=sum(i.bit_count() for i in range(1, n+1))))*k # Chai Wah Wu, Mar 01 2023
(Python)
def A301896(n): return (a:=(n+1)*n.bit_count()+(sum((m:=1<<j)*((k:=n>>j)-(r if n<<1>=m*(r:=k<<1|1) else 0)) for j in range(1, n.bit_length()+1))>>1))*(2+(n+1)*(t:=(n+1).bit_length())-(1<<t)-a) # Chai Wah Wu, Nov 11 2024
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Ilya Gutkovskiy, Mar 28 2018
STATUS
approved