Despite its name, Fermat's Little Theorem is one of Pierre de Fermat's most important theorems. Fermat first presented it without proof in one of his letters in 1640. Leonhard Euler provided the first published proof in 1736. The theorem is very useful as a way of testing very large primes.
In a nutshell, the proof states that given an integer a and a prime p that does not divide a, then we know that a(p-1) has a remainder of 1 when divided by p.
From this theorem, then we know that:
472 ≡ 1 (mod 3).
1106 ≡ 1 (mod 7).
From the basic ideas of modulus (see here for review), we also know that:
(472)n ≡ 1 (mod 3)
(1106)n ≡ 1 (mod 7)
This theorem is also the foundation of Sophie's Proof (see here for the details), an important result from the mathematician Sophie Germain.
Theorem: If an integer a is not divisible by a prime p, then ap-1 ≡ 1 (mod p).
(1) From the Division Algorithm, we know that any number divided by an integer p has a remainder between 0 and p-1.
(2) This means that for any value a there is exactly p-1 possible congruences.
a ≡ 0 (mod p) or
a ≡ 1 (mod p) or
a ≡ p-1 (mod p)
(3) Consider the values 0a, 1a, 2a,... (p-1)a.
(4) It turns out that each of these values (0a, 2a, ...) is equal to a unique congruence when divided by p since:
(a) Assume that 2 of the values are equal to the same congruence: let's say ia, ja
(b) So ia ≡ ja (mod p)
(c) This tells us that p divides ia - ja (from the definition of ≡)
(d) Which means that p divides a(i-j).
(e) From Euclid's Lemma, we know that p must divide i-j (since a is not divisible by p)
(f) But then i = j since both values are between 0 and p.
(5) So, this tells us that:
(1a)(2a)...(p-1)a ≡ (1)(2)...(p-1) (mod p). [Applying the principles of modular arithmetic]
(6) We also know that (1a)(2a)*...*(p-1)a = a(p-1)(p-1)! [See here for a review of factorials such as (p-1)!]
(7) Putting (5) and (6) together gives us:
a(p-1)(p-1)! ≡ (p-1)! (mod p).
(8) Since (p-1)! is not equal to 0, we can divide this from both sides of the modulus (see Lemma 4, here) and get:
a(p-1) ≡ 1 (mod p).