# Formula to calculate how many times a number occurs between two numbers

1. Jun 19, 2010

### Brandon_R

Hello guys, i was just wondering what is the formula to calculate how many times a number occurs between two numbers, both inclusively and exclusively.

Thanks.

2. Jun 19, 2010

### jbunniii

Can you please clarify the question? As far as I know, every (real) number occurs precisely once on the number line.

3. Jun 19, 2010

### Brandon_R

For example:

How many times does the number 7 occur from 1 to 1,000,000 (one to one million) inclusive.

4. Jun 19, 2010

What have you tried so far Brandon?

5. Jun 19, 2010

### Brandon_R

First i counted how many times the digit 7 occured between 1-10 which is one. Then i divided 1,000,000 by 10 and multiplied it by 1. But that's wrong. Is there a formula to solve a question like this? This doesn't account for numbers like 77 or 777.

6. Jun 19, 2010

### Count Iblis

Hint: It is easier to count the number of numbers that do not contain a 7.

7. Jun 19, 2010

### Brandon_R

Thanks.

8. Jun 19, 2010

### Staff: Mentor

I have still no idea what the question is

I guess you are looking for numbers that contain digit seven, or something like that?

9. Jun 19, 2010

### Staff: Mentor

Something like that, Borek. How many numbers between 1 and 1,000,000 contain the digit 7 one or more times.

10. Jun 21, 2010

### gomunkul51

0-99: 1 recurrence of digit 7 (single digit) + 9 (from "ones" in double digit) + 10 (from "tens" in double digit). (1+9+10)=20

100-999: 10 (from "ones" in triple digit numbers) + 90 (from "tens" in triple digit numbers) + 100 (from "hundreds" in triple digit numbers) = 10*(1+9+10)=200

1,000-9,999: again we see: 100*(1+9+10)=2,000

10,000-99,999: again we see: 1,000*(1+9+10)=20,000

100,000-999,999: again we see: 10,000*(1+9+10)=200,000

as a result there are 20*(1+10+100+1,000+10,000) = 222,222 recurrences of the digit 7 in one million numbers.

any close to the answer ? :)

Last edited: Jun 21, 2010
11. Jun 21, 2010

### Staff: Mentor

You're off by quite a lot. You aren't counting the numbers with repeated occurrences of the digit. For example, you are counting numbers such as 7 and 70, but aren't also counting numbers such as 77.
Looking at one of your ranges of numbers, you have 200 numbers in the range 100 through 999 that have 7 digits. I get 252 of them. As stated earlier in this thread it's easier to count how many numbers don't have a 7 digit.

12. Jun 21, 2010

### Brandon_R

Im getting 600,000 occurrences of the digit 7 here.

13. Jun 21, 2010

### Staff: Mentor

I think your value is high by about 70,000. How did you get 600,000?

14. Jun 21, 2010

### Brandon_R

Found it using a not so mathematical approach. I wrote a PHP script to concatenate the numbers 1 to 1 million into a variable ie 1234567891011121314151617...1000000 and then searched for how many times the number 7 occurred.

I just wanted to see how far away i was from the answer.

15. Jun 21, 2010

### gomunkul51

Mark44 its the second time your saying that "it's easier to count how many numbers don't have a 7 digit" but its basically the same, when you count one you basically count the other and i don't really see why its easier. just a thought.

also the number 7 and 70 count as two occurrences because they are two different numbers and each has 1 occurrence of the digit 7.

But you right I counted some numbers twice!
and you're right on the money with 252 :)

Example for 100-999:

(107,117,127,...,197) + (207,...,297) + (307,...,397) + (...) + (907,...,997) = 10*9 = 90
(170,171,..179) + (270,..179) + (...) + (970,..979) = 10*9 -9 (No. 177,277,...,977) = 81
(700,701,...,799) = 100 - 10 (No. 707,717,...,797) - 9 (No. 770-779 without 777) = 81

=> grand total = 90+81+81= 252.

now we're mostly sure how many 7's are in 100-999 :)

16. Jun 21, 2010

### Staff: Mentor

As far as this problem is concerned, the range 1 - 1,000,000 is the same as the range 0 - 999,999.

It's easy enough to count how many times 7 doesn't appear as a digit. In each of the 6 places there are 9 digits that can appear and one (7) that can't appear. So there are 96 numbers that don't have a 7 digit in any of the 6 places. All the rest do have a 7 digit in one or more positions.