15

I know this sounds a bit stupid but this question always confounds me. Say that you are given a range of numbers like $20$-$300$. And it asks you to find how many multiples of $5$ are given in that range. How would you proceed? What would the answers be for inclusive and exclusive numbers?

lennon310
  • 628

6 Answers6

12

$20=5\times 4$ and $300=5\times 60$. So it has from $4$th multiple to $30$th. Thus including $20$ and $300$ it has $60-4+1=57$ multiples. If suppose instead of $300$, you had $x$ on the end where $x$ is not a multiple of $5$ then you just take first multiple of $5$ when you start walking left on integer line from $x$, i.e. if $x=304$, you replace it by $300$ again. similarly for non multiple on beginning, but now walk right.

random
  • 312
  • I can't post this as a separate answer, but for anyone else tackling this problem, for the interval $[a, b]$ and the factor $f$, you walk left exactly $b \bmod f$ and right exactly $(-a) \bmod f$. So a single formula to solve this problem could be $\lfloor \frac{b - b\bmod f - a - (-a) \bmod f}{f} \rfloor + 1$ – creallf Sep 05 '21 at 02:04
8

Hint Count all the numbers such that they end in either a $5$ or a $0$. For the numbers $0-30$ inclusive that is $7$ numbers.

Sarah
  • 298
3

Let the range given be $[x,y]$, and the number whose multiple are to be counted in that range to be $z$,Any multiple of z in range $[x,y]$ would be of form zk,where k is any whole number, hence $x \leq zk \leq y$,which reduces to

$\dfrac xz \leq k \leq \dfrac yz$

now you have got range of k,counting number of multiples of z is equivalent to counting number of integral values of k in this range,that is $$\left\lfloor \frac{y}{z} \right\rfloor - \left\lceil \frac{x}{z} \right\rceil +1$$

applying this to your question

number of multiples of 5 in range [20,300] equals$$\left\lfloor \frac{300}{5} \right\rfloor - \left\lceil \frac{20}{5} \right\rceil +1$$ $$=60-4+1$$ $$=57$$ Note:If the range in (x,y] or [x,y) or (x,y) instead of [x,y], then you have to subtract unwanted mulitples as per the conditions after using above formula

Dheeraj Gujrathi
  • 1,036
  • 4
  • 20
3

This may be logically equivalent to Bhaskar Vashishth’s answer, but IMNSHO this is clearer.

  1. Figure out how many multiples of $5$ there are between $0$ and $300$.  Hint: $\frac{300}5$ may have something to do with this.
  2. Figure out how many multiples of $5$ there are between $0$ and $20$.
  3. Subtract result 2 from result 1.
2

In general one possible thing to do is the following:

rearrange the first and the last number (as in Bhaskar Vashishth's response) so that they are multiples of the number $n$ you want to count multiples of (5 in this case).

Then substract the two numbers, divide by $n$ and add one to get the inclusive answer

jorst
  • 1,555
1

I will provide an example for illustration.

Question: Find the no. of multiples of 4 between 1 and 605, inclusive.

Solution Methodology: The formula can be put down as : (Greatest Multiple of the number in the Range - Smallest multiple of the number in the range ) divided by the number. To this result add 1 to account for inclusivity.

As an expression this can be written as: (GMIR-SMIR)/The Number)+1
Note: GMIR - Greatest Multiple In Range. SMIR- Smallest Multiple In Range.

For the illustration: Greatest multiple of 4 in the range ( 1 to 605) can be found out by dividing 605 by 4. You would get a quotient of 151 and remainder 1. 151 multiplied by 4 is 604. This is the greatest multiple of 4 inside the range.

Smallest multiple of the range can be found by dividing 1 by 4. Answer would be 0. It doesn't fit in the range. So check for the next multiple in the range, which is 4.

Now, use the formula (Greatest Multiple in Range - Smallest Multiple in Range) divided by the number which would be (604-4)/4 equalling 150.

Now add 1 to 150, equalling 151. (We add 1 to account for inclusivity of the extreme multiples).

The answer is 151.

This solution works for any range , inclusive. If not inclusive, you would have to tweak the results to remove the inclusive multiple.

james
  • 11