I'm reading a book and it says the equation
$$ a \bmod n = a - n \left\lfloor\frac{a}{n}\right\rfloor$$
follows that $$ 0 \leq a \bmod n \lt n. $$
I understand that the remainder is less than divisor, but I can't understand how the author got it from the first equation. Could someone, please, explain it to me?
Answer
As $\lfloor x\rfloor \le x<\lfloor x\rfloor +1$, we have
$$ 0\le \frac an-\left\lfloor \frac an\right\rfloor <1$$
and after multiplication with $n$ the claim.
No comments:
Post a Comment