OFFSET
0,4
COMMENTS
This is G_{2, 1/4}(n) in Prodinger's notation.
LINKS
Gheorghe Coserea, Table of n, a(n) for n = 0..10000
Helmut Prodinger, Generalizing the sum of digits function, SIAM J. Algebraic Discrete Methods 3 (1982), no. 1, 35--42. MR0644955 (83f:10009).
MAPLE
A000120 := proc(n) add(i, i=convert(n, base, 2)) end:
# A014081:
cn := proc(v, k) local n, s, nn, i, j, som, kk;
som := 0;
kk := convert(cat(seq(1, j = 1 .. k)), string);
n := convert(v, binary);
s := convert(n, string);
nn := length(s);
for i to nn - k + 1 do
if substring(s, i .. i + k - 1) = kk then som := som + 1 fi od;
som; end;
[seq(n-A000120(n)+cn(n, 2), n=0..100)];
MATHEMATICA
cn[n_, k_] := Count[Partition[IntegerDigits[n, 2], k, 1], Table[1, {k}]]; Table[n - DigitCount[n, 2, 1] + cn[n, 2], {n, 0, 78}] (* Michael De Vlieger, Sep 18 2015 *)
PROG
(PARI)
a(n) = n - hammingweight(n) + hammingweight(bitand(n, n>>1));
vector(79, i, a(i-1)) \\ Gheorghe Coserea, Sep 24 2015
(Python)
def A239904(n): return n-n.bit_count()+(n&(n>>1)).bit_count() # Chai Wah Wu, Feb 12 2023
CROSSREFS
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Apr 06 2014
STATUS
approved