The main goal of today's lecture is to prove the following theorem.
Theorem 1.1 A number

is a sum of two squares if and only if all prime factors of

of the form

have even exponent in the prime factorization of

.
Before tackling a proof, we consider a few examples.
Example 1.2
- <!-- MATH $5 = 1^2 + 2^2$ -->
. -
is not a sum of two squares. -
is divisible by
because
is, but not by
since
is not, so
is not a sum of two squares. - <!-- MATH $2\cdot 3^4\cdot 5\cdot 7^2\cdot 13$ -->
is a sum of two squares. -
is a sum of two squares, since <!-- MATH $389\equiv 1\pmod{4}$ -->
and
is prime. - <!-- MATH $21=3\cdot 7$ -->
is not a sum of two squares even though <!-- MATH $21\equiv 1\pmod{4}$ -->
.
In preparation for the proof of Theorem1.1, we recall a result that emerged when we analyzed how partial convergents of a continued fraction converge.
Lemma 1.3 If <!-- MATH $x\in\mathbb{R}$ -->

and <!-- MATH $n\in\mathbb{N}$ -->

, then there is a fraction <!-- MATH $\displaystyle \frac{a}{b}$ -->

in lowest terms such that

and <!-- MATH \begin{displaymath} \left| x - \frac{a}{b} \right| \leq \frac{1}{b(n+1)}. \end{displaymath} -->
Proof. Let <!-- MATH $[a_0,a_1,\ldots]$ -->
![$ [a_0,a_1,\ldots]$](http://modular.fas.harvard.edu/edu/Fall2001/124/lectures/lecture21/lecture21/img26.png)
be the continued fraction expansion of

. As we saw in the proof of Theorem2.3 in Lecture18, for each

<!-- MATH \begin{displaymath} \left| x - \frac{p_m}{q_m}\right| < \frac{1}{q_m \cdot q_{m+1}}. \end{displaymath} -->
Since

is always at least

bigger than

and

, either there exists an

such that <!-- MATH $q_m\leq n < q_{m+1}$ -->

, or the continued fraction expansion of

is finite and

is larger than the denominator of the rational number

. In the first case, <!-- MATH \begin{displaymath} \left| x - \frac{p_m}{q_m}\right| < \frac{1}{q_m \cdot q_{m+1}} \leq \frac{1}{q_m \cdot (n+1)}, \end{displaymath} -->
so <!-- MATH $\displaystyle \frac{a}{b} = \frac{p_m}{q_m}$ -->

satisfies the conclusion of the lemma. In the second case, just let <!-- MATH $\displaystyle \frac{a}{b} = x$ -->

.

Definition 1.4 A representation <!-- MATH $n=x^2 + y^2$ -->

is
primitive if <!-- MATH $\gcd(x,y)=1$ -->

.
Lemma 1.5 If

is divisible by a prime

of the form

, then

has no primitive representations.
Proof. If

has a primitive representation, <!-- MATH $n=x^2 + y^2$ -->

, then <!-- MATH \begin{displaymath} p \mid x^2 + y^2\quad \text{ and }\quad \gcd(x,y)=1, \end{displaymath} -->

and
so

and

. Thus <!-- MATH $x^2 + y^2 \equiv 0\pmod{p}$ -->

so, since <!-- MATH $\mathbb{Z}/p\mathbb{Z}$ -->

is a field we can divide by

and see that <!-- MATH \begin{displaymath} (x/y)^2 \equiv -1\pmod{p}. \end{displaymath} -->
Thus the quadratic residue symbol <!-- MATH $\left(\frac{-1}{p}\right)$ -->

equals

. However, <!-- MATH \begin{displaymath} \left(\frac{-1}{p}\right) = (-1)^{\frac{p-1}{2}} = (-1)^\frac{4m+3-1}{2} = (-1)^{2m+1} = -1. \end{displaymath} -->
Proof. [Proof of Theorem
1.1] <!-- MATH $\left(\Longrightarrow\right)$ -->

Suppose that

is of the form

, that <!-- MATH $p^r\mid\mid n$ -->

(exactly divides) with

odd, and that

. Letting <!-- MATH $d=\gcd(x,y)$ -->

, we have <!-- MATH \begin{displaymath} x = dx', \quad y = dy', \quad n = d^2 n' \end{displaymath} -->
with <!-- MATH $\gcd(x',y')=1$ -->

and <!-- MATH \begin{displaymath} (x')^2 + (y')^2 = n'. \end{displaymath} -->
Because
is odd,
, so Lemma1.5 implies that <!-- MATH $\gcd(x',y')>1$ -->
, a contradiction.
<!-- MATH $\left(\Longleftarrow\right)$ -->
Write <!-- MATH $n=n_1^2 n_2$ -->
where
has no prime factors of the form
. It suffices to show that
is a sum of two squares. Also note that <!-- MATH \begin{displaymath} (x_1^2 + y_1^2)(x_2^2+y_2^2) = (x_1x_2+y_1y_2)^2 + (x_1y_2-x_2y_1)^2, \end{displaymath} -->
so a product of two numbers that are sums of two squares is also a sum of two squares.
1Also, the prime

is a sum of two squares. It thus suffices to show that if

is a prime of the form

, then

is a sum of two squares.
Since <!-- MATH \begin{displaymath} (-1)^{\frac{p-1}{2}} = (-1)^{\frac{4m+1-1}{2}} = +1, \end{displaymath} -->

is a square modulo

; i.e., there exists

such that <!-- MATH $r^2\equiv -1\pmod{p}$ -->

. Taking <!-- MATH $n=\lfloor \sqrt{p}\rfloor$ -->

in Lemma
1.3 we see that there are integers

such that <!-- MATH $0<b<\sqrt{p}$ -->

and <!-- MATH \begin{displaymath} \left| -\frac{r}{p} - \frac{a}{b}\right| \leq\frac{1}{b(n+1)} < \frac{1}{b\sqrt{p}}. \end{displaymath} -->
If we write <!-- MATH \begin{displaymath} c = rb + pa \end{displaymath} -->
then <!-- MATH \begin{displaymath} |c| < \frac{pb}{b\sqrt{p}} = \frac{p}{\sqrt{p}} = \sqrt{p} \end{displaymath} -->
and <!-- MATH \begin{displaymath} 0 < b^2 + c^2 < 2p. \end{displaymath} -->
But <!-- MATH $c \equiv rb\pmod{p}$ -->

, so <!-- MATH \begin{displaymath} b^2 + c^2 \equiv b^2 + r^2 b^2 \equiv b^2(1+r^2) \equiv 0\pmod{p}. \end{displaymath} -->
Thus <!-- MATH $b^2 + c^2 = p$ -->

.