OFFSET
0,4
FORMULA
a(n) = -A037861(n) for n >= 1.
a(n) = Sum_{i=1..k} (2*b[i] - 1) where b is the binary expansion of n and k is the number of bits in this binary expansion. - Michel Marcus, Jun 28 2021
From Aayush Soni Feb 12 2022: (Start)
Upper bound: a(n) <= floor(log_2(n+1)).
Lower bound: For n > 0, a(n) >= 1 - floor(log_2(n)).
If n is even, a(2^n) to a(2^(n+1)-1) inclusive are all odd and vice versa. (End)
EXAMPLE
From Michel Marcus, Feb 12 2022: (Start)
Viewed as an irregular triangle:
0;
1;
0, 2;
-1, 1, 1, 3;
-2, 0, 0, 2, 0, 2, 2, 4;
-3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1, 3, 1, 3, 3, 5;
... (End)
MAPLE
a:= n-> add(2*i-1, i=Bits[Split](n)):
seq(a(n), n=0..90); # Alois P. Heinz, Jan 18 2022
MATHEMATICA
Join[{0}, Table[Count[#, 1] - Count[#, 0] &[IntegerDigits[n, 2]], {n, 1, 90}]] (* Robert P. P. McKone, Feb 12 2022 *)
PROG
(Haskell)
a145037 0 = 0
a145037 n = a145037 n' + 2*m - 1 where (n', m) = divMod n 2
-- Reinhard Zumkeller, Jun 16 2011
(PARI) A145037(n)=hammingweight(n)*2-logint(n<<1+!n, 2) \\ M. F. Hasler, Mar 08 2018
(Python)
result = [0]
for n in range (1, 2**14 + 1):
result.append(bin(n)[2:].count("1") - bin(n)[2:].count("0"))
print(result[0:129]) # Karl-Heinz Hofmann, Jan 18 2022
(Python)
def a(n): return (n.bit_count()<<1) - n.bit_length()
print([a(n) for n in range(1, 2**14+1)]) # Michael S. Branicky, May 14 2024
(C#)
int A145037(int n) {
int result = 0;
while(n > 0) {
result += 2 * (n % 2) - 1;
n /= 2;
}
return result;
} \\ Frank Hollstein, Dec 08 2022
CROSSREFS
KEYWORD
sign,base,easy
AUTHOR
Reikku Kulon, Sep 30 2008
EXTENSIONS
Renamed (using a Mar 08 2018 comment from M. F. Hasler) and edited by Jon E. Schoenfield, Jun 29 2021
STATUS
approved