Fermats Little Theorem
Introduction
What happens when you raise an integer to a high power and take the remainder modulo a prime? Fermat's little theorem gives a beautiful answer: for any integer
This theorem, stated by Pierre de Fermat in
Understanding Fermat's little theorem leads naturally to Euler's theorem (its generalization to composite moduli) and to modern cryptographic protocols that secure digital communication worldwide.
Statement of the Theorem
Let
An equivalent formulation that holds for all integers
The two forms are equivalent when
Proof by Group Theory
The multiplicative group
By Lagrange's theorem, the order of any element divides the order of the group. Thus for any
Proof by Counting
Consider the products
Multiplying all elements together:
Since
Euler's Generalization
Euler's theorem extends Fermat's result to composite moduli. For any positive integer
where
Applications
RSA Cryptography
RSA encryption relies on a generalization combining Fermat's and Euler's theorems. For
for any message
Fermat Primality Test
The contrapositive of Fermat's theorem gives a primality test: if
However, some composite numbers (called Carmichael numbers) satisfy
The Miller-Rabin test strengthens Fermat's test to avoid Carmichael numbers, and is used in practice for probabilistic primality testing.
Simplifying Modular Exponentiation
Fermat's theorem allows reducing large exponents before computing. To find
Compute
r=k*mod(p-1) Then
ak≡ar*(mod(p))
This dramatically reduces computation for astronomical exponents.
The Converse is False
If
but
Connection to Other Concepts
Fermat's little theorem is a special case of Lagrange's theorem in group theory. The multiplicative group
The theorem also connects to Wilson's theorem:
In algebraic terms, Fermat's theorem says that in the finite field
Summary
Fermat's little theorem states that for prime
The theorem follows from group theory (Lagrange's theorem applied to the multiplicative group) or from a clever counting argument. Euler's theorem
Key applications include:
Computing large powers modulo primes efficiently
Finding modular inverses:
a(−1)≡a(p−2)*(mod(p)) Primality testing (Fermat and Miller-Rabin tests)
RSA cryptography and public-key encryption
The converse fails: passing the Fermat test doesn't guarantee primality (Carmichael numbers exist). Despite this limitation, Fermat's little theorem remains one of the most useful results in number theory.