TITLE: Counting zero-digits between 1 and 1 million
QUESTION [7 upvotes]: I just remembered a problem I read years ago but never found an answer:

Find how many 0-digits exist in natural numbers between 1 and 1 million.

I am a programmer, so a quick brute-force would easily give me the answer, but I am more interested in a pen-and-paper solution.

REPLY [10 votes]: Just to show there is more than one way to do it:
How many zero digits are there in all six-digit numbers? The first digit is never zero, but if we pool all of the non-first digits together, no value occurs more often than the others, so exactly one-tenth of them will be zeroes. There are $9\cdot 5\cdot 10^5$ such digits all of all, and a tenth of them is $9\cdot 5 \cdot 10^4$.
Repeating that reasoning for each possible length, the number of zero digits we find between $1$ and $999999$ inclusive is
$$\sum_{n=2}^6 9(n-1)10^{n-2} = 9\cdot 54321 = 488889 $$
To that we may (depending on how we interpret "between" in the problem statement) need to add the 6 zeroes from 1,000,000 itself, giving a total of 488,895.

REPLY [7 votes]: This solution might appeal to a programmer's mind.  Let's say we zero-pad (to $6$ digits) the million numbers from $0$ to $999999$.  Then each of the $6$ positions uses each digit equally, for a total of $6000000/10 = 600000$ zeros.
Now note that compared to the actual question, we included $000000$, and excluded $1000000$, which balances out nicely.  We just need to undo the zero-padding: there are $9$ positive one-digit numbers which were padded by 5, $90$ two-digit numbers padded by $4$, etc.  What remains is
$$600000 - 5\cdot9 - 4\cdot90 - 3\cdot900 - 2\cdot9000 - 1\cdot90000 = 488895.$$