# Thread: Having trouble figuring out why a certain equation works, any ideas?

1. ## Having trouble figuring out why a certain equation works, any ideas?

Hi All

Given the following numbers

a=2, b=19, c= 3

using the equation:

b/c - (a-1) / c

yields the result of how many numbers between a and b are divisible by c - I have tested this and it seems to work - but I am stumped if I know why?!

b/c gives the amount of times C divides into B using 0 as a base starting point, but what stumps me is the significance of (a-1)/c?

Can anyone give me the break down of it because for reason I just can't get it right in my head!!

Many thanks

2. ## Re: Having trouble figuring out why a certain equation works, any ideas?

The number of multiples of $\displaystyle c$ less than or equal to $\displaystyle b$ is equal to $\displaystyle \lfloor \frac{b}{c} \rfloor$ ($\displaystyle \lfloor x \rfloor$ is the floor value function). We want to subtract the multiples of $\displaystyle c$ that are strictly less than $\displaystyle a$, which is just $\displaystyle \lfloor \frac{a-1}{c} \rfloor$.

Therefore the number of multiples of $\displaystyle c$ between $\displaystyle a$ and $\displaystyle b$, inclusive, is $\displaystyle \lfloor \frac{b}{c} \rfloor - \lfloor \frac{a-1}{c} \rfloor$.

3. ## Re: Having trouble figuring out why a certain equation works, any ideas?

Thank you Richard - much appreciated