# 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 $c$ less than or equal to $b$ is equal to $\lfloor \frac{b}{c} \rfloor$ ( $\lfloor x \rfloor$ is the floor value function). We want to subtract the multiples of $c$ that are strictly less than $a$, which is just $\lfloor \frac{a-1}{c} \rfloor$.

Therefore the number of multiples of $c$ between $a$ and $b$, inclusive, is $\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