Remainder operation in terms of the floor function

336 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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