# Fermat's theorem on sums of two squares

In additive number theory, Pierre de Fermat's theorem on sums of two squares states that an odd prime p is expressible as

$p = x^2 + y^2,\,$

with x and y integers, if and only if

$p \equiv 1 \pmod{4}.$

For example, the primes 5, 13, 17, 29, 37 and 41 are all congruent to 1 modulo 4, and they can be expressed as sums of two squares in the following ways:

$5 = 1^2 + 2^2, \quad 13 = 2^2 + 3^2, \quad 17 = 1^2 + 4^2, \quad 29 = 2^2 + 5^2, \quad 37 = 1^2 + 6^2, \quad 41 = 4^2 + 5^2.$

On the other hand, the primes 3, 7, 11, 19, 23 and 31 are all congruent to 3 modulo 4, and none of them can be expressed as the sum of two squares.

Albert Girard was the first to make the observation (in 1632) [1] and Fermat was first to claim a proof of it. Fermat announced this theorem in a letter to Marin Mersenne dated December 25, 1640; for this reason this theorem is sometimes called Fermat's Christmas Theorem.

Since the Brahmagupta–Fibonacci identity implies that the product of two integers that can be written as the sum of two squares is itself expressible as the sum of two squares, by applying Fermat's theorem to the prime factorization of any positive integer n, we see that if all of n's odd prime factors congruent to 3 modulo 4 occur to an even exponent, it is expressible as a sum of two squares. The converse also holds.

## Proofs of Fermat's theorem on sums of two squares

Fermat usually did not write down proofs of his claims, and he did not provide a proof of this statement. The first proof was found by Euler after much effort and is based on infinite descent. He announced it in a letter to Goldbach on April 12, 1749. Lagrange gave a proof in 1775 that was based on his study of quadratic forms. This proof was simplified by Gauss in his Disquisitiones Arithmeticae (art. 182). Dedekind gave at least two proofs based on the arithmetic of the Gaussian integers. There is an elegant proof using Minkowski's theorem about convex sets. Simplifying an earlier short proof due to Heath-Brown (who was inspired by Liouville's idea), Zagier presented a one-sentence proof of Fermat's assertion.

## Related results

Fermat announced two related results fourteen years later. In a letter to Blaise Pascal dated September 25, 1654 he announced the following two results for odd primes $p$:

• $p = x^2 + 2y^2 \Leftrightarrow p\equiv 1\mbox{ or }p\equiv 3\pmod{8},$
• $p= x^2 + 3y^2 \Leftrightarrow p\equiv 1 \pmod{3}.$

He also wrote:

If two primes which end in 3 or 7 and surpass by 3 a multiple of 4 are multiplied, then their product will be composed of a square and the quintuple of another square.

In other words, if p, q are of the form 20k + 3 or 20k + 7, then pq = x2 + 5y2. Euler later extended this to the conjecture that

• $p = x^2 + 5y^2 \Leftrightarrow p\equiv 1\mbox{ or }p\equiv 9\pmod{20},$
• $2p = x^2 + 5y^2 \Leftrightarrow p\equiv 3\mbox{ or }p\equiv 7\pmod{20}.$

Both Fermat's assertion and Euler's conjecture were established by Lagrange.