I came across this identity $$a\bmod{n}= a - \left\lfloor \frac{a}{n} \right\rfloor \times n$$
I see that it works, but I'm struggling to prove it, so I thought I would ask you guys.
I came across this identity $$a\bmod{n}= a - \left\lfloor \frac{a}{n} \right\rfloor \times n$$
I see that it works, but I'm struggling to prove it, so I thought I would ask you guys.
Copyright © 2021 JogjaFile Inc.
We can write $a \in \mathbb{Z}$ as $kn + b$ with $k, b \in \mathbb{Z}$ and $0 \leq b < n$.
Then $ a = b $ (mod $n$)
and:
$$ nk + b - n\left\lfloor \frac{kn + b}{n}\right\rfloor = nk + b + n\left\lfloor k + \frac{b}{n}\right\rfloor $$
and since $\frac{b}{n} < 1$ because $b < n$ this is equal to:
$$nk + b - n\lfloor k \rfloor = nk + b - nk = b$$