Fermat's Little Theorem

  • For any prime p and integer a not divisible by p: a^(p-1) ≡ 1 (mod p)
  • Reveals primes create regular structure in modular exponentiation via multiplicative cycling
  • Stated by Fermat (1640) without proof; first proven by Euler (1736)
  • Generalizes to Euler's Theorem and emerges from Lagrange's Theorem on multiplicative groups
  • Foundation for modern cryptography, primality testing, and computational number theory
  • Shows why primes are special: only they make all non-zero elements cycle predictably

Fermat's Little Theorem

Overview

Fermat's Little Theorem stands as one of the most elegant and useful results in elementary number theory, establishing a fundamental relationship between prime numbers and modular arithmetic. Despite its deceptively simple statement, this theorem underpins much of modern cryptography, primality testing, and computational number theory. For a first encounter with deep number-theoretic ideas, Fermat's Little Theorem offers the perfect balance: accessible to prove with basic tools, yet profound in its applications.

The theorem tells us something remarkable: when you raise any integer to the power of a prime , then reduce modulo , the result depends only on the original integer modulo , and in particular, if the integer is not divisible by , raising it to the power always yields 1. This is not obvious—why should exponentiation interact so cleanly with division by primes? The answer lies in the structure of modular arithmetic and the properties that make primes special.

Historically, Pierre de Fermat stated this result in a letter to Frénicle de Bessy in 1640, though he provided no proof. The first published proof came from Leonhard Euler in 1736, who later generalized it to the more comprehensive Euler's Theorem. The theorem has since become a cornerstone of algebraic number theory and group theory, where it emerges as a special case of Lagrange's Theorem applied to the multiplicative group of integers modulo a prime.

Fermat's Little Theorem reveals that prime numbers impose a regular, predictable structure on exponentiation: every non-zero element, when raised to the power , becomes 1 modulo . This "multiplicative cycling" is unique to primes and is the foundation for their role in cryptography.

Fermat's Little Theorem: Let be a prime number. Then for any integer not divisible by , we have
Equivalently, for any integer (including those divisible by ), we have

Core Theory

Main Result

Theorem [1] (Fermat's Little Theorem): Let be a prime number and let be an integer with . Then
Theorem [2] (Alternative Formulation): Let be a prime number. Then for any integer ,

We present two proofs of Theorem [1], each illuminating different aspects of the result.

Proof 1 (Combinatorial Argument via Multiplication):

Consider the set of non-zero residues modulo .

Since , multiplication by is a bijection on modulo . That is, the set

is a permutation of when reduced modulo .

To see this: if for , then . Since is prime and , by Euclid's Lemma we have . But , so . Thus all elements of are distinct modulo , and since there are of them, they must be exactly in some order.

Therefore:

This gives us:

Now is not divisible by (since each factor is less than ), so . By the cancellation law in modular arithmetic, we can divide both sides by :

Proof 2 (Group-Theoretic):

Consider the multiplicative group under multiplication modulo . Since is prime, this is indeed a group of order .

By Lagrange's Theorem from group theory, the order of any element divides the order of the group. If , then the order of divides , meaning in the group, which translates to .

Proof of Theorem [2] from Theorem [1]:

If , then by Theorem [1], , so multiplying both sides by gives .

If , then , so . □

Common Error: Fermat's Little Theorem requires to be prime. Students often mistakenly apply it when is composite. For example, with and , we have , not 1. The theorem fails completely for composite moduli (though Euler's Theorem provides the correct generalization using the Euler totient function). Pierre de Fermat (1640) — First stated this theorem in correspondence, claiming to have a proof but never publishing it, launching centuries of investigation into modular arithmetic and prime numbers. Powers of 2 modulo 7 (p = 7) 1 (2⁰) 2 (2¹) 4 (2²) 1 (2³) 2 (2⁴) 4 (2⁵) 2⁶ ≡ 1 (mod 7) Order = p-1 = 6

Examples and Applications

1

Computing large powers efficiently

Calculate .

Solution: Since 11 is prime and , Fermat's Little Theorem tells us that

We write , so:

Without Fermat's Little Theorem, computing directly would be computationally intensive. This theorem reduces the problem dramatically.

2

Finding modular inverses

Find the multiplicative inverse of 7 modulo 13.

Solution: We seek such that .

By Fermat's Little Theorem, . Rewriting:

So is our inverse. We compute efficiently:

Check: . ✓

Thus the inverse of 7 modulo 13 is 2.

Why the prime hypothesis is essential

Consider and (composite). If Fermat's Little Theorem applied to composite moduli, we'd expect .

However, , so , not 1.

The failure occurs because the multiplicative group has order , not . For composite , we must use Euler's Theorem: when . Here , and indeed fails too (it gives ), illustrating that even Euler's theorem requires coprimality!

Actually, , so neither theorem applies. For a valid example: . ✓

Mental Model: The Cyclic Odometer

Imagine an odometer with positions (where is prime) that advances by multiplying by each step, wrapping around modulo . Since is prime, the only way to return to position 1 is if you've hit every non-zero position exactly once (or some divisor's worth of times).

Fermat's Little Theorem guarantees that after exactly steps, you're back at 1. The primality of ensures that multiplication by any creates a permutation of the non-zero residues—there are no "short circuits" or smaller cycles (unless has smaller order dividing ).

Geometrically, think of the non-zero residues as nodes in a cycle graph. Multiplication by is an arrow from each node to another. Primality ensures this graph is strongly connected: starting from 1, you can reach every other node and return, creating a beautiful cyclic symmetry.

Historical Development

Pierre de Fermat first stated this theorem in a letter dated October 18, 1640, to his correspondent Frénicle de Bessy. As was typical for Fermat, he claimed to have a proof but did not provide it, writing instead that he would send the demonstration if Frénicle had trouble finding it himself. No proof from Fermat survives.

The first published proof appeared in 1736 by Leonhard Euler, who recognized the theorem's importance and placed it on rigorous footing. Euler later generalized the result around 1760 to what is now called Euler's Theorem, which applies to composite moduli using the Euler totient function . This generalization states that when , recovering Fermat's Little Theorem as the special case where is prime (since ).

The theorem gained new practical importance in the 20th century with the development of public-key cryptography. The RSA algorithm, invented by Rivest, Shamir, and Adleman in 1977, relies crucially on Fermat's Little Theorem and its generalization for both encryption and efficient computation of modular inverses.

Connections to Other Areas

Connection to Finite Field Theory: Fermat's Little Theorem can be reinterpreted as the statement that in the finite field with elements, every non-zero element satisfies . This connects to the deeper fact that the multiplicative group is cyclic group|cyclic of order . The theorem thus becomes a special case of the general principle that in any finite group, every element's order divides the group order—revealing that elementary number theory and abstract algebra are intimately connected. This perspective extends to Galois theory, where Fermat's Little Theorem helps us understand the Frobenius endomorphism in characteristic .

What You Need First

What This Opens Up

See Also

Euler's Theorem · Wilson's Theorem · Chinese Remainder Theorem · Carmichael's Theorem · Primitive Roots · Quadratic Residues

Before this

  • Modular Arithmetic — The entire theorem is formulated in terms of congruences modulo a prime, requiring fluency with residue classes and modular arithmetic operations.
  • Prime Numbers — Understanding what makes primes special (irreducibility, [[Euclid's Lemma]]) is essential, as the theorem fails for composite moduli.
  • Greatest Common Divisor — The condition $\gcd(a, p) = 1$ is crucial; familiarity with coprimality and the [[Euclidean Algorithm]] helps understand when the theorem applies.

Where this leads

  • Euler's Theorem — The direct generalization replacing $p-1$ with $\phi(n)$, applicable to any modulus, making Fermat's Little Theorem a special case.
  • RSA Cryptography — Modern public-key encryption relies on Fermat's Little Theorem and Euler's generalization for both the mathematical foundation and efficient implementation.
  • Primality Testing — Algorithms like the [[Fermat Primality Test]] and [[Miller-Rabin Primality Test]] use Fermat's Little Theorem as a necessary (though not sufficient) condition for primality, enabling fast probabilistic primality testing for large numbers.