How many multiples of $6$ are there between the following pairs of numbers?
$0$ and $100$ and $-6$ and $34$.
- $16$ and $6$
- $17$ and $6$
- $17$ and $7$
- $16$ and $7$
My attempt:
Total number of integer between $0$ to $100 = 101$ So, total number of multiplier between $0$ to $100 = \left\lfloor\frac{101}{6}\right\rfloor = 16$
And, Total number of integer between $-6$ to $34 = 41$ So, total number of multiplier between $-6$ to $34 = \left\lfloor\frac{34}{6}\right\rfloor = 6$
But, somewhere it explained as:
Number of multiples of $6$ between $1$ and $100 = 100/6 = 16$ Since the range starts from zero, we need to take zero too. [zero is a multiple of every integer (except zero itself)]. So, answer $= 16+1 = 17$ Number of multiples of $6$ between $1$ and $34 = 34/6 = 5$ Since the range is $-6$ to $34$, we need to take $-6$ and zero.
So, answer $= 5+2 = 7$.
However, this small question and we can count on fingers.
But, what is wrong with my approach, can you explain it, please?
Probably the best way to adapt your approach for accuracy is to find the first multiple of $6$ (or in general $d$) in the range. Then adjust the interval if necessary (and it's not necessary in your case), and apply your calculation to just the difference of the adjusted start to the end, to give the additional multiples of $d$ in range.
So given an interval $[s,f]$ how many multiples of $d$? $$\begin{align}s &\to s' \qquad s'\text{ is first multiple of $d$ in range}\\ \text{Multiples: }m &= 1+ \left\lfloor\frac{f-s'}{d}\right\rfloor \end{align}$$