login
If n = Sum_{i=0..m} c(i)*2^i, c(i) = 0 or 1, then a(n) = Sum_{i=0..m} (m+1-i)*c(i).
38

%I #23 Mar 18 2024 05:26:25

%S 0,1,1,3,1,4,3,6,1,5,4,8,3,7,6,10,1,6,5,10,4,9,8,13,3,8,7,12,6,11,10,

%T 15,1,7,6,12,5,11,10,16,4,10,9,15,8,14,13,19,3,9,8,14,7,13,12,18,6,12,

%U 11,17,10,16,15,21,1,8,7,14,6,13,12,19,5,12,11,18,10,17,16,23,4,11,10,17,9,16,15,22,8,15,14

%N If n = Sum_{i=0..m} c(i)*2^i, c(i) = 0 or 1, then a(n) = Sum_{i=0..m} (m+1-i)*c(i).

%C Suggested by Jon Perry's A231204, only now the leading power of 2 gets weight 1.

%H Rémy Sigrist, <a href="/A230877/b230877.txt">Table of n, a(n) for n = 0..8192</a>

%e For n=13 we have 1101, so we add 1+2+4, getting a(13)=7.

%p f:=proc(n) local t1,m,i;

%p t1:=convert(n,base,2);

%p m:=nops(t1)-1;

%p add((m+1-i)*t1[i+1], i=0..m);

%p end;

%t Array[Total[Position[IntegerDigits[#, 2], 1], 2] &, 100, 0] (* _Paolo Xausa_, Mar 18 2024 *)

%o (PARI) a(n) = { my (b=binary(n)); sum(k=1, #b, b[k]*k) } \\ _Rémy Sigrist_, Jun 25 2021

%o (Python)

%o def A230877(n): return sum(i for i, j in enumerate(bin(n)[2:],1) if j=='1') # _Chai Wah Wu_, Jan 09 2023

%Y Cf. A029931, A231204, A329752.

%K nonn,base

%O 0,4

%A _N. J. A. Sloane_, Nov 08 2013