A239906 Let cn(n,k) denote the number of times 11..1 (k 1's) appears in the binary representation of n; a(n) = n - cn(n,1) + cn(n,2) - cn(n,3).
0, 0, 1, 2, 3, 3, 5, 5, 7, 7, 8, 9, 11, 11, 12, 12, 15, 15, 16, 17, 18, 18, 20, 20, 23, 23, 24, 25, 26, 26, 27, 27, 31, 31, 32, 33, 34, 34, 36, 36, 38, 38, 39, 40, 42, 42, 43, 43, 47, 47, 48, 49, 50, 50, 52, 52, 54, 54, 55, 56, 57, 57, 58, 58, 63, 63, 64, 65, 66, 66, 68, 68, 70, 70, 71, 72, 74, 74
Offset: 0
Links
- Michael De Vlieger, Table of n, a(n) for n = 0..10000
Programs
-
Maple
# From 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-cn(n,1)+cn(n,2)-cn(n,3), n=0..100)];
-
Mathematica
cn[n_, k_] := Count[Partition[IntegerDigits[n, 2], k, 1], Table[1, {k}]]; Table[n - Sum[cn[n, i], {i, 1, 3, 2}] + cn[n, 2], {n, 0, 77}] (* Michael De Vlieger, Sep 18 2015 *)
-
PARI
a(n) = { my(x = bitand(n, n>>1), wt = k->hammingweight(k)); n - wt(n) + wt(x) - wt(bitand(x, n>>2)); }; vector(78, i, a(i-1)) \\ Gheorghe Coserea, Sep 24 2015