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

  • Thread starter Thread starter Brandon_R
  • Start date Start date
  • Tags Tags
    Formula Numbers
Brandon_R
Messages
26
Reaction score
1
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.
 
Physics news on Phys.org
Can you please clarify the question? As far as I know, every (real) number occurs precisely once on the number line.
 
For example:

How many times does the number 7 occur from 1 to 1,000,000 (one to one million) inclusive.
 
Brandon_R said:
For example:

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

What have you tried so far Brandon?
 
First i counted how many times the digit 7 occurred 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.
 
Hint: It is easier to count the number of numbers that do not contain a 7.
 
Thanks.
 
I have still no idea what the question is :bugeye:

I guess you are looking for numbers that contain digit seven, or something like that?
 
Borek said:
I have still no idea what the question is :bugeye:

I guess you are looking for numbers that contain digit seven, or something like that?
Something like that, Borek. How many numbers between 1 and 1,000,000 contain the digit 7 one or more times.
 
  • #10
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:
  • #11
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
Im getting 600,000 occurrences of the digit 7 here.
 
  • Like
Likes jpbollozos
  • #13
I think your value is high by about 70,000. How did you get 600,000?
 
  • #14
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
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
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.
 

Similar threads

Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
17
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 20 ·
Replies
20
Views
2K