login
A393336
a(n) is the sum of positions of 1's minus sum of positions of 0's in the binary expansion of n.
4
-1, 1, 1, 3, 0, 2, 4, 6, -2, 0, 2, 4, 4, 6, 8, 10, -5, -3, -1, 1, 1, 3, 5, 7, 3, 5, 7, 9, 9, 11, 13, 15, -9, -7, -5, -3, -3, -1, 1, 3, -1, 1, 3, 5, 5, 7, 9, 11, 1, 3, 5, 7, 7, 9, 11, 13, 9, 11, 13, 15, 15, 17, 19, 21, -14, -12, -10, -8, -8, -6, -4, -2, -6, -4, -2
OFFSET
0,4
COMMENTS
A weighted variant of A037861.
Position 1 corresponds to the least significant bit of n.
Conjecture: the sequence contains all integers.
Above conjecture is true. All positive integers are attained when n in binary is of the form 101010...10. All nonpositive integers are attained when n in binary is of the form 1001010101..01. - Chai Wah Wu, Feb 27 2026
LINKS
FORMULA
a(n) = A029931(n) - A359400(n).
a(n) = A029931(n) - A029931(A035327(n)).
a(n) = 2*A029931(n)-A070939(n)*(A070939(n)+1)/2. - Chai Wah Wu, Feb 26 2026
EXAMPLE
a(6) = 4, because 6 = 110_2, and -1+2+3 = 4.
a(8) = -2, because 8 = 1000_2, and -1-2-3+4 = -2.
MAPLE
a:= n-> (l-> add(`if`(l[i]=0, -i, i), i=1..nops(l)))(convert(n, base, 2)):
seq(a(n), n=0..74); # Alois P. Heinz, Feb 26 2026
MATHEMATICA
A393336[n_] := Total[#*Range[Length[#], 1, -1]] & [2*IntegerDigits[n, 2] - 1];
Array[A393336, 100, 0] (* Paolo Xausa, Feb 26 2026 *)
PROG
(PARI) a(n)= my(d=Vecrev([ b-!b |b<-if(n, binary(n), [0])])); d*[1..#d]~
(PARI) a(n)= my(d=binary(n)); 2*d*-[-#d..-1]~ - binomial(#d+1, 2) - !n \\ Ruud H.G. van Tol, Feb 27 2026
(Python)
from math import comb
def A393336(n): return (sum(i if j == '1' else 0 for i, j in enumerate(bin(n)[:1:-1], 1))<<1)-comb(n.bit_length()+1, 2) if n else -1 # Chai Wah Wu, Feb 26 2026
CROSSREFS
Cf. A006257, A029931, A035327, A037861, A147991, A359400, A360099, A392980 (positions of zeros).
Cf. A309983.
Sequence in context: A145856 A092154 A177344 * A139585 A273084 A349728
KEYWORD
sign,easy,base
AUTHOR
Ruud H.G. van Tol, Feb 12 2026
STATUS
approved