We now return to Fermat's theorem.
Fermat discovered many beautiful results on prime numbers.
Here we shall study a theorem called "Fermat's Little Theorem."
We call it "Little" in order to distinguish it from Fermat's Last Theorem.
However, contrary to its name, it is simple but very useful.
It has many applications to Number Theory and Cryptography.
Here is a statement of Fermat's Little Theorem.
Let P be a prime number.
Take an integer A greater than or equal to 1, and less than or equal to P - 1.
Then, the theorem says A^P - 1 is always congruent to 1 modulo P.
For example, if P is 5 and A is 2, the fourth power of 2 is 16, and 16 is congruent to 1 modulo 5.
If P is 11 and A is 3, 3^10 is 59,049,
which is congruent to 1 modulo 11.
We shall give a proof of Fermat's Little Theorem.
The idea of the proof is similar to the proof of the existence of the multiplicative inverses.
First, consider A times B modulo P for B varying from 1 to P - 1.
We have already seen these numbers are not congruent to each other modulo P.
Therefore, if we take the product of all the A times B for varying B from 1 to P - 1, it is congruent to the product of all integers from 1 to P - 1.
This means A^P - 1 times the factorial of P - 1 is congruent to the factorial of P - 1.
Here the factorial of P - 1 is the product of all integers from 1 to P - 1.
A^P - 1 minus 1 times the factorial of P - 1 is congruent to zero modulo P.
Since P is a prime number, this means A^P - 1 is congruent to 1 modulo P.
In the proof of Fermat's Little Theorem, the factorial of P - 1 plays an important role.
This number modulo P can be calculated by Wilson's Theorem.
Next, we shall prove Wilson's Theorem.
There are several proofs of it.
We shall prove it using Lagrange's Theorem on roots of polynomials modulo P.
Here is a statement of Wilson's Theorem.
For any prime number P, the factorial of P - 1 is congruent to -1 modulo P.
Let me give you some examples.
It is easy to check Wilson's Theorem if P is 2 or 3.
If P is 7, the factorial of 6 is equal to 720.
Then you can check 720 is congruent to -1 modulo P
because the difference 721 is divisible by 7.
The following is Lagrange's Theorem.
It looks a little bit complicated,
but the actual meaning of the theorem is rather simple.
Fix a prime number P.
Consider a polynomial F(X) of degree D.
The coefficients are integers.
The theorem says, if A is a root of F(X) modulo P,
then the polynomial F(X) can be written as a product of X - A and another polynomial G(X) modulo P.
This is a modulo P analogue of usual results on roots of polynomials.
The second statement of the theorem says if we have K roots modulo P of the polynomial F(X),
then F(X) can be written as the product of (X - A)'s and another polynomial H(X).
In particular, the number of roots of F(X) is less than or equal to the degree.
The proof of Lagrange's Theorem goes as follows.
Consider the polynomial F(X) of degree D.
If we put X is A, then F(A) becomes as follows.
Therefore, by a simple calculation, the difference is divisible by X - A.
Since we have assumed F(A) is congruent to zero modulo P,
we see that F(X) is written as the product of X - A and another polynomial G(X).
This proves the first assertion.
The second assertion is proved by induction on the number of roots, K.
Now we can prove Wilson's Theorem combining Fermat's Little Theorem and Lagrange's Theorem.
Since Wilson's Theorem is obvious when P is 2, we may assume P is an odd prime number.
By Fermat's Little Theorem, A^P - 1 is congruent to 1 modulo P for any P from 1 to P - 1.
All the integers from 1 to P - 1 are roots of the polynomial X^P - 1 minus 1 modulo P.
By Lagrange's Theorem, we conclude that X^P - 1 minus 1 must be equal to the product of X - 1, X - 2, ..., and X - (P - 1).
Therefore, comparing the constant terms of both hand sides,
we see that -1 is congruent to (-1)^P - 1 times the factorial of P - 1.
Since P is an odd prime, (-1)^P - 1 is 1.
Hence it is congruent to the factorial of P - 1.
The proof of Wilson's Theorem is complete.
Finally, let me give an application of Lagrange's Theorem.
The following theorem will be very important when we study Modular Arithmetic in more detail in the next week.
Fix a prime number P and a positive integer D.
Then, there are at most D elements A
such that A^D minus 1 is congruent to 0 modulo P.
For the proof, we put F(X) is X^D minus 1.
Then, if A^D minus 1 is congruent to 0 modulo P,
F(A) is congruent to 0 modulo P.
By Lagrange's Theorem, the number of such elements must be less than or equal to D.
