88 ELEMENTARY NUMBER THEORY
Theorem 5.1 Fermat's theorem. Let p be a prime and suppose that p ,.r a. Then
ap-l = 1 (mod p).
Proof. We begin by considering the first p- 1 positive multiples of a; that is, the
integers
a , 2a , 3a , ... , (p - l)a
None of these numbers is congruent modulo p to any other, nor is any congruent to
zero. Indeed, if it happened that
ra = sa (mod p)
then a could be canceled to give r =s (mod p), which is impossible. Therefore, the
previous set of integers must be congruent modulo p to 1, 2 , 3 , ... , p - 1, taken in
some order. Multiplying all these congruences together, we find that
a 2a 3a (p - l)a = 1 2 3 (p - 1) (mod p)
whence
aP-1 (p - l)! = (p - 1)! (mod p)
Once (p - l)! is canceled from both sides of the preceding congruence (this is possible
because since p ,.r (p - l)!), our line of reasoning culminates in the statement that
l
ap- = 1 (mod p), which is Fermat's theorem.
This result can be stated in a slightly more general way in which the requirement
that p l a is dropped.
Corollary. If p is a prime, then aP =a (mod p) for any integer a.
Proof. p I a, the statement obviously holds; for, in this setting, aP = 0 =a
When
(mod p). If p ,.r a, then according to Fermat's theorem, we have aP-l = 1 (mod p).
When this congruence is multiplied by a, the conclusion aP =a (mod p) follows.
There is a different proof of the fact that aP = a (mod p), involving induction
on a. If a= 1, the assertion is that IP= 1 (mod p), which clearly is true, as is the
case a= 0. Assuming that the result holds for a, we must confirm its validity for
a + 1. In light of the binomial theorem,
(a + l)P = aP + (n ap- l + + u) ap-k + + (/ ) I
a + 1
where the coefficient ( f ) is given by
() p
k -
p!
k!(p -k)!
p(p - 1)... (p -k + 1)
1 . 2. 3 .. k
Our argument hinges on the observation that ( f) = 0 (mod p) for 1 ::=: k ::=: p - 1.
To see this, note that
k! U) = p(p - 1)- -(p -k + 1) = 0 (mod p)