[Math] Calculating the number of times a digit is written when given two numbers

algebra-precalculus

My homework asks me the following:

If a student writes the integers from 5 to 305 inclusive by hand, how many times will she write the digit 5?

I started out by writing every number that contains 5 and I got 31, but 31 is not among the answers possible:

5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215, 225, 235, 245, 255, 265, 275, 285, 295, 305

I counted 55, 155, and 255 as two each since there are two occurrences of the digit 5 in each. I can't figure out what I'm doing wrong.

In addition, suppose I were given the numbers 1 and 100,000 – writing them out isn't efficient, and I would assume there's a formula for this but I can't figure that out either.

Best Answer

Count 000 up to 299. Of the 300 unit digits, $\frac1{10}$ are 5. Of the 300 tens digits, $\frac1{10}$ are 5. None of the hundreds digits are 5. Adding the one in 305, I count 61=30+30+1 in the integers from 5 to 305.