Corollary (criterion for sum of two squares)

Let $n\in \Z$ have prime factorisation $n = p_1^{n_1} \ldots p_k^{n_k}$.

$n$ can be written as the sum of two squares iff $n_i$ is even whenever $p_i \equiv 3\pmod 4$.

Proof