Three Theorems in Number Theory

In this post, I would like to discuss three elementary theorems in number theory that I first learned in my middle school. It has been really ages since then, and I only vaguely remember their proofs.

During a rather boring midnight coach ride from the airport, I found myself with nothing to do but share some random mathematical thoughts with my wife. As the journey went on, the proofs gradually became clearer in my mindโ€”and, meanwhile, she happily fell asleep.

Letโ€™s start with Fermatโ€™s little theorem.

Theorem 1 (Fermat). Let ๐‘ be a prime number. For any ๐‘Ž coprime to ๐‘, we have ๐‘Ž๐‘โˆ’1=1(mod๐‘).

Proof. Let ๐‘†={1,2,โ€ฆ,๐‘โˆ’1}. We notice that the set ๐‘Ž๐‘†โ‰”{๐‘Ž,2๐‘Ž,โ€ฆ,๐‘Ž(๐‘โˆ’1)} coincides with ๐‘†, since ๐‘Ž and ๐‘ are coprime. We immediately get

(๐‘โˆ’1)!=โˆ๐‘›โˆˆ๐‘†๐‘›=โˆ๐‘›โˆˆ๐‘Ž๐‘†๐‘›=๐‘Ž๐‘โˆ’1(๐‘โˆ’1)!(mod๐‘).

After canceling out (๐‘โˆ’1)! on both sides of the equation, we derive ๐‘Ž๐‘โˆ’1=1(mod๐‘).โ โˆŽ

The next theorem also involves a double counting technique.

Theorem 2 (Wilson). Let ๐‘ be a prime number. We have (๐‘โˆ’1)!=โˆ’1(mod๐‘).

Proof. The elements in ๐‘†={1,2,โ€ฆ,๐‘โˆ’1} can be grouped into pairs (๐‘Ž,๐‘Žโˆ’1), where ๐‘Žโˆ’1 is the unique element such that ๐‘Žโ‹…๐‘Žโˆ’1=1(mod๐‘). There are only two special cases where ๐‘Ž=๐‘Žโˆ’1, namely ๐‘Ž=1 or ๐‘Ž=๐‘โˆ’1. So, when we compute โˆ๐‘›โˆˆ๐‘†๐‘›, almost all the terms in the same pair cancel out and only leave 1 and ๐‘โˆ’1. Therefore, we derive

(๐‘โˆ’1)!=1โ‹…(๐‘โˆ’1)=โˆ’1(mod๐‘).

โ โˆŽ

The last theorem is also named after Fermat. But, as usual, he did not write down the proof. The first proof was given by Euler using infinite descent. Here, I present a more constructive proof.

Theorem 3 (Sum of two squares). A prime number ๐‘ can be represented as a sum of two squares if and only if ๐‘=1(mod4).

Proof. The necessity is obvious. Now, we assume that ๐‘=1(mod4). By Wilsonโ€™s theorem, we have (๐‘โˆ’1)!=โˆ’1(mod๐‘). In particular, it yields

โˆ’1=(๐‘โˆ’1)!=โˆ๐‘›=1๐‘โˆ’12๐‘›โ‹…(๐‘โˆ’๐‘›)=(โˆ’1)๐‘โˆ’12โˆ๐‘›=1๐‘โˆ’12๐‘›2=(โˆ๐‘›=1๐‘โˆ’12๐‘›)2(mod๐‘).

Therefore, there exists ๐‘Ž such that ๐‘Ž2=โˆ’1(mod๐‘).

Let ๐‘›=โŒŠ๐‘โŒ‹ and we consider the set ๐ด={0,๐‘Ž,โ€ฆ,๐‘›๐‘Ž}. Since |๐ด|=๐‘›+1, by pigeonhole principle, there must be two elements (๐‘ฅ๐‘Ž,๐‘ฆ๐‘Ž) in ๐ด such that ๐‘ฅ๐‘Žโˆ’๐‘ฆ๐‘Ž=๐‘ง(mod๐‘) for some 0<๐‘งโ‰ค๐‘›. We notice that

0<(๐‘ฅโˆ’๐‘ฆ)2+๐‘ง2โ‰ค๐‘›2+๐‘›2<2๐‘.

Moreover, by our choice of ๐‘Ž,

(๐‘ฅโˆ’๐‘ฆ)2+๐‘ง2=(๐‘ฅโˆ’๐‘ฆ)2+(๐‘ฅ๐‘Žโˆ’๐‘ฆ๐‘Ž)2=(๐‘ฅโˆ’๐‘ฆ)2(๐‘Ž2+1)=0(mod๐‘).

We deduce that (๐‘ฅโˆ’๐‘ฆ)2+๐‘ง2=๐‘.

โ โˆŽ