I find I am in trouble to prove:
$$(a + b) \bmod n = (a \bmod n + b \bmod n) \bmod n ?$$
Can anyone help?
I find I am in trouble to prove:
$$(a + b) \bmod n = (a \bmod n + b \bmod n) \bmod n ?$$
Can anyone help?
Let $a = hn + (a \bmod n)$, $b = kn + (b \bmod n)$, $h,k\in \mathbb Z$. Then the left hand side
$$\begin{align*} (a+b)\bmod n =& [a+b-(h+k)n]\bmod n\\ =& [(hn +a\bmod n) + (kn+b\bmod n) - hn - kn]\bmod n\\ =& (a\bmod n + b\bmod n)\bmod n \end{align*}$$
There is a simple proof using the following: \begin{equation} x\bmod{n}=y\bmod{n} \Longleftrightarrow n \mid (x-y). \end{equation}
Let $r = a\bmod{n}$ and $s=\bmod{n}$. By the Division Algorithm, there are integers $p$ and $q$ such that $a = pn + r$ and $b = qn + s$. Adding these equations and rewriting yields $n(p+q) = (a + b) -(r + s)$. The result now follows by the fact above.
$$(a+b) \equiv (a+b-n) \equiv (a+b-2n)\equiv \ldots \pmod n$$
or when considering $\bmod$ as an operator,
$$(a+b)\bmod n = (a+b-n)\bmod n = (a+b-2n)\bmod n = \ldots$$
On the first equal sign, I just chose to subtract $n$ multiple times, specifically $(h+k)$ times.
– peterwhy Sep 12 '21 at 19:51