login
Number of 1's in decimal expansion of 2^n.
15

%I #26 Apr 16 2020 10:20:38

%S 1,0,0,0,1,0,0,1,0,1,1,0,0,1,1,0,0,2,1,0,1,1,1,0,2,0,1,2,0,1,2,1,0,0,

%T 3,0,1,1,0,1,3,1,3,0,3,1,1,1,2,2,2,2,0,1,3,1,0,4,4,0,3,1,3,0,3,3,0,2,

%U 2,3,6,3,1,0,2,3,3,5,1,1,5,3,1,2,5,1,4,2,2,5,2,0,5,3,1,6,2,2,4,5,2

%N Number of 1's in decimal expansion of 2^n.

%C 2^17 = 131072 so a(17)=2.

%H Harry J. Smith, <a href="/A065712/b065712.txt">Table of n, a(n) for n = 0..1000</a>

%t Table[ Count[ IntegerDigits[2^n], 1], {n, 0, 100} ]

%t Table[DigitCount[2^n,10,1],{n,0,120}] (* _Harvey P. Dale_, Aug 15 2014 *)

%o (PARI) Count(x, d)= { local(c=0, f); while (x>9, f=x-10*(x\10); if (f==d, c++); x\=10); if (x==d, c++); return(c) }

%o { for (n=0, 1000, a=Count(2^n, 1); write("b065712.txt", n, " ", a) ) } \\ _Harry J. Smith_, Oct 26 2009

%o (PARI) a(n) = #select(x->(x==1), digits(2^n)); \\ _Michel Marcus_, Jun 15 2018

%o (Python)

%o def A065712(n):

%o return str(2**n).count('1') # _Chai Wah Wu_, Feb 14 2020

%Y Cf. 0's A027870, 3's A065714, 4's A065715, 5's A065716, 6's A065717, 7's A065718, 8's A065719, 9's A065744.

%K nonn,base

%O 0,18

%A _Benoit Cloitre_, Dec 04 2001

%E More terms from _Robert G. Wilson v_, Dec 07 2001