A337319 a(n) = Sum_{i = 1..floor(log_2(n))+1} g(frac(n/2^i)), where g(t) = [0 if t = 0, -1 if 0 < t < 1/2, 1 if t >= 1/2], and where frac(x) denotes the fractional part.
1, 1, 2, 1, 1, 2, 3, 1, 0, 1, 2, 2, 2, 3, 4, 1, -1, 0, 1, 1, 1, 2, 3, 2, 1, 2, 3, 3, 3, 4, 5, 1, -2, -1, 0, 0, 0, 1, 2, 1, 0, 1, 2, 2, 2, 3, 4, 2, 0, 1, 2, 2, 2, 3, 4, 3, 2, 3, 4, 4, 4, 5, 6, 1, -3, -2, -1, -1, -1, 0, 1, 0, -1, 0, 1, 1, 1, 2, 3, 1
Offset: 1
Keywords
Examples
For n = 10, a(10) = 0 + 1 + (-1) + 1 = 1.
Programs
-
JavaScript
var k = 1; var r = 0; for (var i = 0; i < 100; i += 1) { while ((i+1) >= Math.pow(2, k - 1)) { if (Math.round((i+1) / Math.pow(2, k)) < ((i+1) / Math.pow(2, k))) { r -= 1; } else if (Math.round((i+1) / Math.pow(2, k)) > ((i+1) / Math.pow(2, k))) { r += 1; } else { r += 0; } k += 1; } document.write(r, ", "); k = 1; r = 0; }
-
Mathematica
Array[2 DigitCount[#, 2, 1] + IntegerExponent[#, 2] - Floor[Log2[#]] - 1 &, 80] (* Michael De Vlieger, Sep 01 2020 *)
-
PARI
a(n) = sum(k = 1, 1+logint(n, 2), my(x=(n % 2^k)/2^k); sign(round(x) - x)); \\ Michel Marcus, Aug 23 2020
-
PARI
a(n) = 2*hammingweight(n) + valuation(n,2) - logint(n,2) - 1; \\ Kevin Ryde, Aug 29 2020
Comments