Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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$.

share|improve this answer

Isnt this similar to $\lfloor (Z - Y) / 3\rfloor$

http://maths-on-line.blogspot.in/

share|improve this answer
    
It is close, but you could be off by 1. Consider $Y=1,Z=10$, for example. Because the interval is closed, $\lfloor (Z - Y +1) / 3\rfloor$ is better, but still not always right. –  Ross Millikan Dec 8 '12 at 2:59

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.