A126205 Number of 3's in decimal expansion of 3^n, with n>=0.
0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1, 0, 1, 3, 2, 1, 1, 1, 1, 0, 0, 4, 1, 3, 1, 1, 0, 1, 1, 3, 1, 1, 0, 3, 2, 3, 2, 4, 1, 2, 3, 4, 0, 4, 2, 3, 3, 0, 7, 2, 2, 4, 4, 3, 2, 3, 4, 5, 6, 2, 4, 8, 3, 1, 2, 6, 3, 4, 5, 4, 3, 2, 6, 5, 4, 8, 0, 4, 4, 7, 2, 4, 3, 6, 5, 8, 5, 3, 7, 3, 2, 4, 5
Offset: 0
Examples
a(21)=3 because 3^21=10460353203 with three 3's.
Programs
-
Maple
P:=proc(n) local i,k,x,y,w,cont; y:=3; k:=y; for i from 0 by 1 to n do x:=y^i; cont:=0; while x>0 do w:=x-trunc(x/10)*10; if w=k then cont:=cont+1; fi; x:=trunc(x/10); od; print(cont); od; end: P(100);
-
Mathematica
DigitCount[3^Range[0,100],10,3] (* Harvey P. Dale, May 26 2015 *)