As an example, let's count zeroes in integers from 1 to 12345. You can do this by separately counting how many times a zero appears in each digit position, and sum these counts.
Let's look at the last position first: a zero appears there in integers 10, 20, 30, ..., 90, 100, 110, ..., 12330, 12340. That's 1234 times in total, which is by the way exactly the first four digits of our number 12345.
Next let's look at the next-to-last digit. All numbers with a zero there are of the form xyz0w, where x,y,z,w are some digits. 1 <= xyz0w <= 12345 if and only if 1 <= xyz <= 123, and 0 <= w <= 9, which means that there are 123 ways to choose the digits xyz, and 10 ways to choose w. The total number of ways to choose xyz and w is product 123*10=1230 -- and this is the number of times a zero appears in the next-to-last digit of all integers between 1 and 12345.
You can go similarly with other digit positions. The formula for (k+1)-st digit from the right is (a prefix of 12345 of length 4-k) * 10^k.
Number of zeros in integers from n to m is the number of zeros in 1..m minus the number of zeros in 1..(n-1).
scott1991 wrote:i'm only 16
You're old enough to understand all this stuff, IMHO.
Belorusian informatics whiz (
tourist), IOI's gold medalist, is only 13.
