Integer as Sum of Two Squares

Theorem
Let $$n$$ be a positive integer.

Then $$n$$ can be expressed as the sum of two squares iff each of its prime divisors of the form $$4 k + 3$$ (if any) occur to an even power.

Proof
Let us extract the largest square divisor of $$n$$, and write:
 * $$n = m^2 r$$

where $$r$$ is square-free.

Necessary Condition
Suppose $$r$$ has no prime divisor in the form $$4 k + 3$$.

If $$r = 1$$ then $$n^2 = m^2 + 0^2$$ and nothing needs to be proved.

If $$r > 1$$ then $$r$$ is a product of one or more primes, each of which is either $$2$$ or in the form $$4 k + 1$$.

Now from Prime as Sum of Two Squares, each of these can be expressed as the sum of two squares.

By Product of Sums of Squares, the product of all these can itself be expressed as the sum of two squares.

So $$r = a^2 + b^2$$, say.

Then $$n = m^2 \left({a^2 + b^2}\right) = \left({m a}\right)^2 + \left({m b}\right)^2$$.

So $$n$$ can be expressed as the sum of squares.

Sufficient Condition
Now suppose that $$n$$ can be expressed as the sum of squares, say $$n = m^2 r = a^2 + b^2$$.

First, any common divisor of $$a$$ and $$b$$ may be cancelled as follows.