<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] If both $a$ and $b$ are odd numbers then $a = 2k_1+1, b=2 k_2+1$ and you have that
$$
a^2+b^2 = (2k_1+1)^2+(2 k_2+1)^2 = 4k_1^2+4 k_2^2 +4k_1+4k_2+2 \equiv 2 (mod\,\, 4)
$$
If one is odd (for instance $a$) and the other is even, then $a =2 k_1+1, b=2k_2$ and
$$
a^2+b^2 = (2k_1+1)^2+(2k_2)^2 = 4k_1^2+4k_2^2+4k_1+1\equiv 1 (mod\,\,4)
$$
If both $a$ and $b$ are even, $a=2k_ 1, b=2k_2$ and
$$
a^2+b^2 = (2k_1)^2+(2k_2)^2=4k_1^2+ 4k_2^2 \equiv 0(mod\,\,4)
$$
So you see that $a^2+b^2$ can only be congruent with 0,1 or 2 (mod 4) and is congruent with 0 if and only if both $a$ and $b$ are even numbers.
</s>