How many multiples of X lie in the arbitrary range [Y,Z]? Is there a way to determine this without brute force?
For example
$X=3$
range $= [17,24]$
The multiples of $X$ in this range are $18$, $21$, and $24$, so $3$ multiples total.
 A: The smallest integer $n_1$ such that $n_1X \geq Y$ is $n_1=\lceil Y/X \rceil$, and the largest integer $n_2$ such that $n_2X \leq Z$ is $n_2 = \lfloor Z/X\rfloor$.  The number of integers between $n_1$ and $n_2$ inclusive is $\max\{n_2 - n_1 + 1,0\}$, so putting that together, we get
$$\max\{\lfloor Z/X\rfloor - \lceil Y/X \rceil + 1, 0\}.$$
In your example, $X=3$, $Y=17$, and $Z=24$, so we have
$$\max\{\lfloor 24/3\rfloor - \lceil 17/3 \rceil + 1, 0\} = \max\{8-6+1,0\} = 3$$ multiples of $3$ between $17$ and $24$.
A: Isnt this similar to $\lfloor (Z  - Y) / 3\rfloor$
http://maths-on-line.blogspot.in/
A: An easy way to find out the number of multiples of X in the range [Y,Z] is:
($\lfloor$Z/X$\rfloor$ - $\lfloor$(Y-1)/X$\rfloor$)
The (Y-1) is for the case where Y is divisible by X
In your example, the answer would be computed as: ($\lfloor$24/3$\rfloor$ - $\lfloor$(17-1)/3$\rfloor$) = 8 -$\lfloor$5.666...$\rfloor$ = 3
A: find the smallest $Y1$ such that $Y1 \% X == 0$ and $Y1 >= Y$. similarly, find the greatest $Z1$ such that $Z1 \% X == 0$ and $Z1 <= Z$.
Once you have $Y1$ and $Z1$ with you, it's easy:
The number of divisors of $X$ in range $[Y, Z]$ is same as in range $[Y1, Z1]$ which is $((Z1 - Y1) / X) + 1$.
Running this logic on your example:
$X = 3, Y = 17, Z = 24 => Y1 = 18, Z1 = 24 => (Z1 - Y1) = 6$
hence, the number of divisors of $3$ in range $[17, 24]$ are $(6 / 3) + 1 = 3$
