# Sums of Squares

## Representation Problems

One of the oldest questions in number theory asks which integers can be written as sums of squares. Typical examples are

$$
5=1^2+2^2,
$$

$$
25=3^2+4^2,
$$

and

$$
50=1^2+7^2.
$$

Such problems are called representation problems because they ask how integers may be represented by quadratic forms.

The simplest equation of this type is

$$
x^2+y^2=n,
$$

where $n$ is a fixed positive integer and $x,y\in\mathbb{Z}$.

$$
x^2+y^2=n
$$

The goal is to determine for which integers $n$ the equation has integer solutions.

## Squares Modulo Small Integers

Congruences provide strong restrictions on sums of squares.

Modulo $4$, every square is congruent to either $0$ or $1$:

$$
0^2\equiv0,\qquad 1^2\equiv1,\qquad 2^2\equiv0,\qquad 3^2\equiv1\pmod4.
$$

Hence a sum of two squares can only be congruent to

$$
0,1,2\pmod4.
$$

Therefore no integer congruent to $3\pmod4$ can be written as a sum of two squares.

For example,

$$
7\equiv3\pmod4,
$$

so the equation

$$
x^2+y^2=7
$$

has no integer solutions.

Congruence arguments of this kind are fundamental throughout number theory.

## Fermat’s Theorem on Two Squares

The complete characterization of primes representable as sums of two squares is given by the following theorem.

**Theorem.** An odd prime $p$ can be written in the form

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

with integers $x,y$ if and only if

$$
p\equiv1\pmod4.
$$

For example,

$$
5=1^2+2^2,
$$

$$
13=2^2+3^2,
$$

$$
17=1^2+4^2,
$$

$$
29=2^2+5^2.
$$

But primes such as

$$
3,7,11,19
$$

cannot be expressed as sums of two squares because they are congruent to $3\pmod4$.

This theorem was stated by entity["people","Pierre de Fermat","French mathematician"] and later proved rigorously by entity["people","Leonhard Euler","Swiss mathematician"].

## The General Criterion

The condition for arbitrary integers is more subtle.

**Theorem.** A positive integer $n$ can be expressed as a sum of two squares if and only if every prime congruent to

$$
3\pmod4
$$

appears with even exponent in the prime factorization of $n$.

For example,

$$
45=3^2\cdot5.
$$

The prime $3\equiv3\pmod4$ appears with exponent $2$, which is even. Indeed,

$$
45=3^2+6^2.
$$

Now consider

$$
21=3\cdot7.
$$

Both primes are congruent to $3\pmod4$, and both appear with odd exponent. Therefore $21$ cannot be represented as a sum of two squares.

## Infinite Families of Solutions

Suppose

$$
a^2+b^2=n
$$

and

$$
c^2+d^2=m.
$$

Then

$$
(ac-bd)^2+(ad+bc)^2=nm.
$$

This identity shows that the product of two sums of squares is again a sum of two squares.

The identity may be written compactly as

$$
(a^2+b^2)(c^2+d^2)
=
(ac-bd)^2+(ad+bc)^2.
$$

This formula explains why factorization plays a central role in the theory.

It also reflects multiplication in the Gaussian integers

$$
\mathbb{Z}[i],
$$

where

$$
i^2=-1.
$$

Indeed,

$$
(a+bi)(c+di)
=
(ac-bd)+(ad+bc)i.
$$

The norm satisfies

$$
N(a+bi)=a^2+b^2,
$$

and multiplication of norms yields the identity above.

## Lagrange’s Four-Square Theorem

The study of sums of squares extends naturally beyond two variables.

A fundamental result states that every positive integer can be written as a sum of four squares.

**Theorem.** For every positive integer $n$, there exist integers $a,b,c,d$ such that

$$
n=a^2+b^2+c^2+d^2.
$$

$$
n=a^2+b^2+c^2+d^2
$$

For example,

$$
31=1^2+1^2+2^2+5^2.
$$

This theorem was proved by entity["people","Joseph-Louis Lagrange","French mathematician"] in the eighteenth century.

The analogous problem for three squares is more delicate. Certain integers cannot be represented as sums of three squares, specifically those of the form

$$
4^k(8m+7).
$$

## Geometric Interpretation

The equation

$$
x^2+y^2=n
$$

describes a circle of radius $\sqrt n$. The problem asks which circles contain lattice points.

Similarly,

$$
x^2+y^2+z^2=n
$$

describes a sphere in three dimensions.

Thus the arithmetic theory of sums of squares becomes a problem about the distribution of lattice points on geometric surfaces. This interaction between algebra, geometry, and arithmetic is a recurring theme in modern number theory.

