Lemma13.5.1
If \(N\) has only primes of the form \(4k+1\) and \(2\) as factors, it is writeable as a sum of two squares.
There is one loose end. What are all the numbers we can represent as a sum of squares?
For instance, why are some composite numbers of the form \(4k+1\) not writeable as the sum of two squares? Also, many even numbers are representable – how do we tell which even numbers are writeable? We conclude our discussion by proving the full statement, after a couple of preliminary lemmas.
If \(N\) has only primes of the form \(4k+1\) and \(2\) as factors, it is writeable as a sum of two squares.
Consider this: \begin{equation*}2\cdot 13\cdot 17=442 = \left(1^2+1^2\right)\left( 3^2+2^2\right)\cdot 17 \end{equation*}\begin{equation*}= \left[\left(1\cdot 3-1\cdot 2\right)^2+\left(1\cdot 2+1\cdot 3\right)^2\right]\left(4^2+1^2\right)\end{equation*} \begin{equation*}=\left(1^2+5^2\right)\left(4^2+1^2\right)=\left(1\cdot 4-5\cdot 1\right)^2+\left(1\cdot 1+5\cdot 4\right)^2=1^2+21^2\end{equation*}
If \(N\) only has prime factors of the form \(4k+3\) to even powers, it is writeable as a sum of two squares.
Consider this: \begin{equation*}35802=442\cdot 3^4 = \left(1^2+21^2\right)3^2\cdot 3^2\end{equation*}\begin{equation*}=1^2\cdot 3^2\cdot 3^2+21^2\cdot 3^2\cdot 3^2=9^2+189^2\end{equation*}
\(N\) can be written as a sum of two perfect squares precisely if it has only even powers (including zeroth powers) of any primes of the form \(4k+3\).
If this still seems too neat and dried, it can be instructive to get insight by plugging in different \(n\) below. When do you get an error, when not?
(As a bonus, can you turn this into an interactive cell? See Sage note 12.6.6.)