Chapter 4
The Theorems of Fermat and Wilson

4.1 Fermat’s General Theorem

Let m be any positive integer and let

a1,a2,,aφ(m) (A)

be the set of φ(m) positive integers not greater than m and prime to m. Let a be any integer prime to m and form the set of integers

aa1,aa2,,aaφ(m) (B)

No number aai of the set (B) is congruent to a number aaj, unless j = i; for, from

aai aaj mod m

we have ai aj mod m; whence ai = aj since both ai and aj are positive and not greater than m. Therefore j = i. Furthermore, every number of the set (B) is congruent to some number of the set (A). Hence we have congruences of the form

aa1 ai1 mod m, aa2 ai2 mod m, aaφ(m) aiφ(m) mod m.

No two numbers in the second members are equal, since aaiaaj unless i = j. Hence the numbers ai1,ai2,,aiφ(m) are the numbers a1,a2,,aφ(m) in some order. Therefore, if we multiply the above system of congruences together member by member and divide each member of the resulting congruence by a1 a2aφ(m) (which is prime to m), we have

aφ(m) 1 mod m.

This result is known as Fermat’s general theorem. It may be stated as follows:

If m is any positive integer and a is any integer prime to m, then

aφ(m) 1 mod m.

COROLLARY 1. If a is any integer not divisible by a prime number p, then

ap1 1 mod p.

COROLLARY 2. If p is any prime number and a is any integer, then

ap a mod p.

4.2 Euler’s Proof of the Simple Fermat Theorem

The theorem of Cor. 1, § 4.1, is often spoken of as the simple Fermat theorem. It was first announced by Fermat in 1679, but without proof. The first proof of it was given by Euler in 1736. This proof may be stated as follows:

From the Binomial Theorem it follows readily that

(a + 1)p ap + 1 mod p

since

p! r!(p r)!,0 < r < p,

is obviously divisible by p. Subtracting a + 1 from each side of the foregoing congruence, we have

(a + 1)p (a + 1) ap a mod p.

Hence if ap a is divisible by p, so is (a + 1)p (a + 1). But 1p 1 is divisible by p. Hence 2p 2 is divisible by p; and then 3p 3; and so on. Therefore, in general, we have

ap amodp.

If a is prime to p this gives ap1 1modp, as was to be proved.

If instead of the Binomial Theorem one employs the Polynomial Theorem, an even simpler proof is obtained. For, from the latter theorem, we have readily

(α1 + α2 + + αa)p α 1p + α 2p + + α ap modp.

Putting α1 = α2 = = αa = 1 we have

ap amodp,

from which the theorem follows as before.

4.3 Wilson’s Theorem

From the simple Fermat theorem it follows that the congruence

xp1 1modp

has the p 1 solutions 1, 2, 3, , p 1. Hence from the discussion in §3.4 it follows that

xp1 (x 1)(x 2)(x p 1¯)modp,

this relation being satisfied for every value of x. Putting x = 0 we have

(1) = (1)p1 1 2 3p 1¯modp.

If p is an odd prime this leads to the congruence

1 2 3p 1¯ + 1 = 0modp.

Now for p = 2 this congruence is evidently satisfied. Hence we have the Wilson theorem:

Every prime number p satisfies the relation

1 2 3p + 1¯ + 1 0modp.

An interesting proof of this theorem on wholly different principles may be given. Let p points be distributed at equal intervals on the circumference of a circle. The whole number of p-gons which can be formed by joining up these p points in every possible order is evidently

1 2pp(p 1)(p 2)3 2 1;

for the first vertex can be chosen in p ways, the second in p 1 ways, , the (p 1)th in two ways, and the last in one way; and in counting up thus we have evidently counted each polygon 2p times, once for each vertex and for each direction from the vertex around the polygon. Of the total number of polygons 1 2(p 1) are regular (convex or stellated) so that a revolution through 360 p brings each of these into coincidence with its former position. The number of remaining p-gons must be divisible by p; for with each such p-gon we may associate the p 1 p-gons which can be obtained from it by rotating it through successive angles of 360 p . That is,

1 2pp(p 1)(p 2)3 2 1 1 2(p 1) 0 mod p.

Hence

(p 1)(p 2)3 2 1 p + 1 0 mod p;

and from this it follows that

1 2p 1¯ + 1 0 mod p,

as was to be proved.

4.4 The Converse of Wilson’s Theorem

Wilson’s theorem is noteworthy in that its converse is also true. The converse may be stated as follows:

Every integer n such that the congruence

1 2 3n 1¯ + 1 0 mod n

is satisfied is a prime number.

For, if n is not prime, there is some divisor d of n different from 1 and less than n. For such a d we have 1 2 3n 1¯ 0 mod d; so that 1 2n 1¯ + 10 mod d; and hence 1 2n 1¯ + 1 0 mod n. Since this contradicts our hypothesis the truth of the theorem follows.

Wilson’s theorem and its converse may be combined into the following elegant theorem:

A necessary and sufficient condition that an integer n is prime is that

1 2 3n 1¯ + 1 0 mod n.

Theoretically this furnishes a complete and elegant test as to whether a given number is prime. But, practically, the labor of applying it is so great that it is useless for verifying large primes.

4.5 Impossibility of 1 2 3n 1¯ + 1 = nk for n > 5.

In this section we shall prove the following theorem:

There exists no integer k for which the equation

1 2 3n 1¯ + 1 = nk

is true when n is greater than 5.

If n contains a divisor d different from 1 and n, the equation is obviously false; for the second member is divisible by d while the first is not. Hence we need to prove the theorem only for primes n.

Transposing 1 to the second member and dividing by n 1 we have

1 2 3n 2¯ = nk1 + nk2 + + n + 1.

If n > 5 the product on the left contains both the factor 2 and the factor 1 2(n 1); that is, the first member contains the factor n 1. But the second member does not contain this factor, since for n = 1 the expression nk1 + n + 1 is equal to k0. Hence the theorem follows at once.

4.6 Extension of Fermat’s Theorem

The object of this section is to extend Fermat’s general theorem and incidentally to give a new proof of it. We shall base this proof on the simple Fermat theorem, of which we have already given a simple independent proof. This theorem asserts that for every prime p and integer a not divisible by p, we have the congruence

ap1 1 mod p.

Then let us write

ap1 = 1 + hp. (1)

Raising each member of this equation to the p th power we may write the result in the form

ap(p1) = 1 + h 1p2. (2)

where h1 is an integer. Hence

ap(p1) 1 mod p2.

By raising each member of (2) to the p th power we can readily show that

ap2(p1) 1 mod p3.

It is now easy to see that we shall have in general

apα1(p1) 1 mod pα.

where α is a positive integer; that is,

aφ(pα) 1 mod pα.

For the special case when p is 2 this result can be extended. For this case (1) becomes

a = 1 + 2h.

Squaring we have

a2 = 1 + 4h(h + 1).

Hence,

a2 = 1 + 8h 1, (3)

where h1 is an integer. Therefore

a2 1 mod 23.

Squaring (3) we have

a22 = 1 + 24h 2;

or

a22 1 mod 24.

It is now easy to see that we shall have in general

a2α2 1 mod 2α

if α > 2. That is,

a1 2 φ(2α) 1 mod 2α  if a > 2. (4.1)

Now in terms of the φ-function let us define a new function λ(m) as follows:

λ(2α) = φ(2α)  if a = 0,1,2; λ(2α) = 1 2φ(2α)  if a > 2; λ(pα) = φ(pα)  if p is an odd prime; λ(2αp 1α1 p2α2 pnαn ) = M,

where M is the least common multiple of

λ(2α),λ(p 1α1 ),λ(p2α2 ),,λ(pnαn ),

2,p1,p2,,pn being different primes.

Denote by m the number

m = 2αp 1α1 p2α2 pnαn .

Let a be any number prime to m. From our preceding results we have

aλ(2α) 1 mod 2α, aλ(p1α1) 1 mod p1α1 , aλ(p2α2) 1 mod p2α2 , aλ(pnαn) 1 mod p2αn .

Now any one of these congruences remains true if both of its members are raised to the same positive integral power, whatever that power may be. Then let us raise both members of the first congruence to the power λ(m) λ(2α); both members of the second congruence to the power λ(m) λ(p1α1); ; both members of the last congruence to the power λ(m) λ(pnαn). Then we have

aλ(m) 1mod2α, aλ(m) 1modp 1α1 , aλ(m) 1modp nαn .

From these congruences we have immediately

aλ(m) 1modm.

We may state this result in full in the following theorem:

If a and m are any two relatively prime positive integers, the congruence

aλ(m) 1modm.

is satisfied.

As an excellent example to show the possible difference between the exponent λ(m) in this theorem and the exponent φ(m) in Fermat’s general theorem, let us take

m = 26 33 5 7 13 17 19 37 73.

Here

λ(m) = 24 32,φ(m) = 231 310.

In a later chapter we shall show that there is no exponent ν less than λ(m) for which the congruence

aν = 1modm

is verified for every integer a prime to m.

From our theorem, as stated above, Fermat’s general theorem follows as a corollary, since λ(m) is obviously a factor of φ(m),

φ(m) = φ(2α)φ(p 1α1 )φ(pnαn ).

EXERCISES

1.
Show that a16 1 mod 16320, for every a which is prime to 16320.
2.
Show that a12 1 mod 65520, for every a which is prime to 65520.
3*.
Find one or more composite numbers P such that

 

aP1 1 mod P

for every a prime to P. (Compare this problem with the next section.)

4.7 On the Converse of Fermat’s Simple Theorem

The fact that the converse of Wilson’s theorem is a true proposition leads one naturally to inquire whether the converse of Fermat’s simple theorem is true. Thus, we may ask the question: Does the existence of the congruence 2n1 1 mod n require that n be a prime number? The Chinese answered this question in the affirmative and the answer passed unchallenged among them for many years. An example is sufficient to show that the theorem is not true. We shall show that

2340 1 mod 341

although 341 = 11 31, is not a prime number. Now 210 1 = 3 11 31. Hence 210 1 mod 341. Hence 2340 1 mod 341. From this it follows that the direct converse of Fermat’s theorem is not true. The following theorem, however, which is a converse with an extended hypothesis, is readily proved.

If there exists an integer a such that

an1 1 mod n

and if further there does not exist an integer ν less than n 1 such that

aν 1 mod n,

then the integer n is a prime number.

For, if n is not prime, φ(n) < n 1. Then for ν = φ(n) we have aν 1 mod n, contrary to the hypothesis of the theorem.

4.8 Application of Previous Results to Linear Congruences

The theorems of the present chapter afford us a ready means of writing down a solution of the congruence

ax c mod m. (1)

We shall consider only the case in which a and m are relatively prime, since the general case is easily reducible to this one, as we saw in the preceding chapter.

Since a and m are relatively prime we have the congruences

aλ(m) 1,aφ(m) 1 mod m.

Hence either of the numbers x,

x = caλ(m)1,x = caφ(m)1,

is a representative of the solution of (1). Hence the following theorem:

If

ax c mod m

is any linear congruence in which a and m are relatively prime, then either of the numbers x,

x = caλ(m)1,x = caφ(m)1,

is a representative of the solution of the congruence.

The former representative of the solution is the more convenient of the two, since the power of a is in general much less in this case than in the other.

EXERCISE

Find a solution of 7x 1 mod 26 3 5 17. Note the greater facility in applying the first of the above representatives of the solution rather than the second.

4.9 Application of the Preceding Results to the Theory of Quadratic Residues

In this section we shall apply the preceding results of this chapter to the problem of finding the solutions of congruences of the form

αz2 + βz + γ 0modμ

where α,β,γ,μ are integers. These are called quadratic congruences.

The problem of the solution of the quadratic congruence (1) can be reduced to that of the solution of a simpler form of congruence as follows: Congruence (1) is evidently equivalent to the congruence

4α2z2 + 4αβz + 4αγ 0mod4αμ. (1)

But this may be written in the form

(2αz + β)2 β2 4αγmod4αμ.

Now if we put

2αz + β xmod4αμ (2)

and

β2 4αγ = a,4αμ = m,

we have

x2 amodm. (3)

We have thus reduced the problem of solving the general congruence (1) to that of solving the binomial congruence (3) and the linear congruence (2). The solution of the latter may be effected by means of the results of §4.8. We shall therefore confine ourselves now to a study of congruence (3). We shall make a further limitation by assuming that a and m are relatively prime, since it is obvious that the more general case is readily reducible to this one.

The example

x2 3mod5

shows at once that the congruence (3) does not always have a solution. First of all, then, it is necessary to find out in what cases (3) has a solution. Before taking up the question it will be convenient to introduce some definitions.

DEFINITIONS. An integer a is said to be a quadratic residue modulo m or a quadratic non-residue modulo m according as the congruence

x2 = amodm

has or has not a solution. We shall confine our attention to the case when m > 2.

We shall now prove the following theorem:

I. If a and m are relatively prime integers, a necessary condition that a is a quadratic residue modulo m is that

a1 2 λ(m) 1modm.

Suppose that the congruence x2 = amodm has the solution x = α. Then a2 amodm. Hence

aλ(m) a1 2 λ(m) modm.

Since a is prime to m it is clear from α2 amodm that a is prime to m. Hence αλ(m) 1modm. Therefore we have

1 a1 2 λ(m) modm.

That is, this is a necessary condition in order that a shall be a quadratic residue modulo m.

In a similar way one may prove the following theorem:

II. If a and m are relatively prime integers, a necessary condition that a is a quadratic residue modulo m is that

a1 2 φ(m) 1modm.

When m is a prime number p each of the above results takes the following form: If a is prime to p and is a quadratic residue modulo p, then

a1 2 (p1) 1modp.

We shall now prove the following more complete theorem, without the use of I or II.

III. If p is an odd prime number and a is an integer not divisible by p, then a is a quadratic residue or a quadratic non-residue modulo p according as

a1 2(p 1) +1 ora1 2(p 1) 1 mod p.

This is called Euler’s criterion.

Given a number a, not divisible by p, we have to determine whether or not the congruence

x2 a mod p

has a solution. Let r be any number of the set

1,2,3,,p 1 (A)

and consider the congruence

rx a mod p. (4.2)

This has always one and just one solution x equal to a number s of the set (A). Two cases can arise: either for every r of the set (A) the corresponding s is different from r or for some r of the set (A) the corresponding s is equal to r. The former is the case when a is a quadratic non-residue modulo p; the latter is the case when a is a quadratic residue modulo p. We consider the two cases separately.

In the first case the numbers of the set (A) go in pairs such that the product of the numbers in the pair is congruent to a modulo p. Hence, taking the product of all 1 2(p 1) pairs, we have

1 2 3p 1¯ +a1 2(p 1) mod p.

But

1 2 3p 1¯ = 1 mod p.

Hence

a1 2(p 1) 1 mod p,

whence the truth of one part of the theorem.

In the other case, namely that in which some r and corresponding s are equal, we have for this r

r2 a mod p

and

(p r)2 a mod p.

Since x2 a mod p has at most two solutions it follows that all the integers in the set (A) except r and p r fall in pairs such that the product of the numbers in each pair is congruent to a modulo p. Hence, taking the product of all these pairs, which are 1 2(p 1) 1 in number, and multiplying by r(p r) we have

1 2 3p 1¯ (p r)ra1 2 (p1)1 mod p r2a1 2 (p1)1 mod p aa1 2 (p1)1 mod p a1 2 (p1) mod p.

Since 1 2 3p 1¯ modp we have

a1 2 (p1) +1 mod p

whence the truth of another part of the theorem.

Thus the proof of the entire theorem is complete.