# Why counting the number of 1 digits that appear in all integers in 0-9, 0-99, 0-999, 0-9999 follow an arithemtic-geometric sequence?

I noticed that

• 0-9 = has only 1 '1'
• 0-99 = has 20 '1's [1,10,11,12,13,14,15,16,17,18,19,21,31,41,51,61,71,81,91]
• 0-999 = 300
• 0-9999 = 4000

It follows the formula of

• n = number of digits in the sequence
• Formula : n*(10**(n-1))

I don't see why.

I hope the question is well formatted

• It isn't an arithmetic sequence (neither as a function of $n$ nor as a function of $10^n-1$). Aug 1, 2022 at 19:31
• Might be easier to count the strings that do NOT have a 1. Aug 1, 2022 at 19:32
• @Randall notice that the OP counted 20, not 19 for the examples in the range 0-99. That is to say, $11$ counted twice since it had two 1's in it, not just once. Yours is a good observation if we were counting each number only once but it is unhelpful here. Aug 1, 2022 at 19:44
• This kind of sequence is called an arithmetico–geometric sequence. Aug 2, 2022 at 5:43
• @JMoravitz Your comment also answers the question why, in larger ranges, the number of 1 digits exceeds the number of numbers. Aug 2, 2022 at 6:29

For the purpose of this question, let's consider that a number between $$0$$ and $$999...9$$ = $$10^n-1$$ ($$n$$ digits $$9$$) is always written with $$n$$ digits, by adding leading zeros when necessary.
Then all numbers from $$0$$ to $$10^n-1$$ included are the combinations of digits from $$0$$ to $$9$$ in $$n$$ places. The $$1$$ on digit $$k$$ is present on $$10^{n-1}$$ numbers, exactly on one-tenth of all numbers. As there are $$n$$ digits, there are $$n 10^{n-1}$$ digits $$1$$ in total.
Another way of saying it: with the leading zeros, there is a same quantity of each digit. As there are $$10^n$$ numbers of $$n$$ digits each, this makes a total of $$n 10^n$$ digits, where one tenth of that, i.e. $$n 10^{n-1}$$, are $$1$$.