A094798 Number of times 1 is used in writing out all the numbers 1 through n.
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18
Offset: 1
Links
- Harvey P. Dale, Table of n, a(n) for n = 1..1000
Programs
-
Maple
nones:=proc(n) local nn,c,j: nn:=convert(n,base,10): c:=0: for j to nops(nn) do if nn[j]=1 then c:=c+1 else end if end do: c end proc: a:=proc(n) options operator, arrow: add(nones(k),k=1..n) end proc: seq(a(n),n=1..75); # Emeric Deutsch, Mar 01 2008 ListTools:-PartialSums([seq(numboccur(1,convert(n,base,10)),n=1..100)]); # Robert Israel, Oct 28 2016
-
Mathematica
Accumulate[Table[DigitCount[n,10,1],{n,80}]] (* Harvey P. Dale, Sep 27 2013 *)
-
PARI
a(n) = sum(k=1, n, #select(x->(x==1), digits(k))); \\ Michel Marcus, Oct 03 2023
-
Python
from itertools import accumulate, count, islice def f(, n): return + str(n).count("1") def agen(): yield from accumulate(count(1), f) print(list(islice(agen(), 75))) # Michael S. Branicky, Aug 09 2022
Formula
G.f. g(x) satisfies g(x) = x/((1-x)*(1-x^10)) + ((1-x^10)/(1-x))^2*g(x^10). - Robert Israel, Oct 28 2016 [corrected by Fabio VisonĂ , Aug 10 2022]
Comments