OFFSET
1,2
COMMENTS
Or, total number of digits in numbers from 1 through n.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..10000
GeeksforGeeks, Count total number of digits from 1 to n
Eric Weisstein's World of Mathematics, Smarandache Number
FORMULA
a(n) = (n+1)*floor(log_10(10*n)) - (10^floor(log_10(10*n))-1)/(10-1).
a(n) = a(n-1) + floor(log_10(10*n)).
a(n) ~ n log_10 n + O(n). In particular lim inf (n log_10 n - a(n))/n = (1+log(10/9)+log(log(10)))/log(10) and the corresponding lim sup is 10/9. - Charles R Greathouse IV, Sep 19 2012
G.f.: (1-x)^(-2)*Sum_{j>=0} x^(10^j). - Robert Israel, Nov 04 2015
a(n) = b(n)*(n + 1) - (10^b(n) - 19)/9 - 2, where b(n) = A055642(n). - Lorenzo Sauras Altuzarra, May 09 2020
EXAMPLE
a(12) = 15 since 123456789101112 has 15 digits.
MAPLE
a:= proc(n) a(n):= `if`(n=0, 0, a(n-1) +length(n)) end:
seq(a(n), n=1..100); # Alois P. Heinz, Nov 26 2013
a := proc(n) local d; d:=floor(log10(n))+1; (n+1)*d - (10^d-1)/9; end; # N. J. A. Sloane, Feb 20 2020
MATHEMATICA
Length/@ Flatten/@ IntegerDigits/@ Flatten/@ Rest[FoldList[List, {}, Range[70]]] (* Eric W. Weisstein, Nov 04 2015 *)
Table[With[{d = IntegerLength[n]}, (n+1) d - (10^d -1)/9], {n, 70}] (* Eric W. Weisstein, Nov 06 2015 *)
IntegerLength/@ FoldList[#2 + #1 10^IntegerLength[#2] &, Range[70]] (* Eric W. Weisstein, Nov 06 2015 *)
Accumulate[ IntegerLength@ # & /@ Range @ 70] (* Robert G. Wilson v, Jul 31 2018 *)
PROG
(PARI) a(n)=my(t=log(10*n+.5)\log(10)); n*t+t-10^t\9 \\ Charles R Greathouse IV, Sep 19 2012
(PARI) a(n) = sum(k=1, n, #digits(k)); \\ Michel Marcus, Jan 01 2017
(Python)
def A058183(n): return (n+1)*(s:=len(str(n))) - (10**s-1)//9 # Chai Wah Wu, May 02 2023
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Henry Bottomley, Nov 17 2000
STATUS
approved