<s>[INST] Proving that $a,b$ are even integers I'm trying to prove the following theorem:

Let $a,b\in\mathbb{Z}$ . Then  $$a^{2}+b^{2}\equiv0\pmod 4 \iff a \;\text{and}\; b\;\text{are even}$$

I always struggle to prove some number is odd or even. How to prove it?
I thought of using the $(a+b)^2=a^2+2ab+b^2$ formula but not sure how.
 [/INST] $\Rightarrow$:
By the rules of modular arithmetic we have
\begin{align}
0 
&= (a^2 + b^2) \bmod 4 \\
&= \left( \left( a^2 \bmod 4 \right) + \left( b^2 \bmod 4 \right)  \right) \bmod 4
\end{align}
For each summand we have
\begin{align}
x^2 \bmod 4
&= \left( \left( x \bmod 4 \right)  \left( x \bmod 4 \right)  \right) \bmod 4 \\
&\in 
\{ y^2 \bmod 4 \mid y \in \{0,1,2,3\} \} 
= \{ 0, 1 \} \quad (*)
\end{align}
So for the expression
$$
\left( \left( a^2 \bmod 4 \right) + \left( b^2 \bmod 4 \right)  \right) \bmod 4
$$
we have the possible cases $0+0$, $0+1$, $1+0$ and $1+1$. This vanishes modulo $4$ only for the case $0+0$.
Now $x^2 \bmod 4$ only vanishes for $x \bmod 4 \in \{ 0, 2 \}$, see display $(*)$, which means
$x = 4k$ or $x = 4k + 2$ for some integer $k$ and both cases can be divided by $2$, thus are even.
$\Leftarrow$:
$a = 2p$ and $b=2q$ for some integers $p, q$. Then we have
\begin{align}
(a^2 + b^2) \bmod 4 
&= (4p^2 + 4q^2) \bmod 4 \\
&= \left( \left(4p^2 \bmod 4\right) + \left(4q^2 \bmod 4 \right)\right) \bmod 4 \\ 
&= (0 + 0) \bmod 4 \\
&= 0
\end{align}
</s>