login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Sum of the number of ones in binary representation of n and n^2.
0

%I #9 Nov 22 2013 14:23:21

%S 0,2,2,4,2,5,4,6,2,5,5,8,4,7,6,8,2,5,5,8,5,9,8,7,4,8,7,10,6,9,8,10,2,

%T 5,5,8,5,9,8,11,5,8,9,11,8,12,7,9,4,8,8,9,7,12,10,12,6,10,9,12,8,11,

%U 10,12,2,5,5,8,5,9,8,11,5,9,9,13,8,11,11,10,5,9

%N Sum of the number of ones in binary representation of n and n^2.

%C The sequence is never 1 or 3, but seems to take on all other values. The fact it is never 3 can be used to prove if n^2 has exactly 4 1's then it must have an even number of 0's (A231898).

%F a(n) = A159918(n) + A000120(n).

%e 5 is 101 and 25 is 11001, so a(5) = 2 + 3 = 5.

%o (JavaScript)

%o function bitCount(n) {

%o var i,c,s;

%o c=0;

%o s=n.toString(2);

%o for (i=0;i<s.length;i++) if (s.charAt(i)==1) c++;

%o return c;

%o }

%o for (i=0;i<100;i++) document.write(bitCount(i*i)+bitCount(i)+", ");

%Y Cf. A000120, A159918, A077436, A094694, A231898, A232243.

%K nonn,base

%O 0,2

%A _Jon Perry_, Nov 20 2013