Skip to content

Fermat's Little Theorem

For prime p, every integer a satisfies a^p ≡ a modulo p; nonzero residues satisfy a^(p−1) ≡ 1.

Version
v1 · 2026-10-03 · History
Domain-specific #
13225
Aliases
Fermats Little Theorem, Fermat Theorem Mod P

Core Idea

For a prime p, Fermat's little theorem says a^p ≡ a (mod p) for every integer a. When a is not divisible by p, it also says a^(p−1) ≡ 1 (mod p). The second form uses the fact that a nonzero residue modulo a prime is invertible; it is false if a is zero modulo p. The p−1 exponent reflects the p−1 nonzero residue classes.[ref-030f7fd649bd][ref-0a8f46550a53]

Scope of Application

With a known prime modulus, the theorem simplifies powers and yields a^(p−2) as the inverse of a nonzero a. For an unknown candidate n, a coprime base that fails a^(n−1) ≡ 1 (mod n) proves n composite. A passing base does not prove primality: composite Carmichael numbers, including 561, can pass for every coprime base.[ref-030f7fd649bd][ref-df555e024ba4]

Clarity

The logic runs from prime to congruence, not from congruence to prime. A failed necessary condition refutes primality, while a passed one is inconclusive. Also keep the two formulas' base conditions separate: at p=5, a=5, the all-integer form gives 5^5 ≡ 5 ≡ 0, but 5^4 ≡ 0, not one.[ref-030f7fd649bd][ref-df555e024ba4]

Manages Complexity

For a nonzero residue modulo a known prime, exponents can be simplified modulo p−1 rather than expanded term by term. The finite unit-group explanation compresses many calculations into one rule. The compression remains safe only while “known prime” and “nonzero base” stay attached to it.[^ref-030f7fd649bd]

Abstract Reasoning

First establish whether the modulus is prime and whether the base is a unit. If both hold, use a^(p−1) ≡ 1 to simplify powers or derive an inverse; if the base is zero, use only a^p ≡ a. If testing a candidate rather than working under a proven prime premise, treat a failing congruence as a compositeness witness and a pass as unresolved. This avoids a false primality certificate.[ref-030f7fd649bd][ref-df555e024ba4]

Knowledge Transfer

The same theorem applies across prime-residue calculations, inverse reasoning and one-way primality screening. Euler's theorem generalizes the unit-group pattern with exponent φ(n) for broader moduli, but that does not license blindly replacing p by a composite in the p−1 formula.

[^ref-030f7fd649bd]: Jonathan A. Poritz, Yet Another Introductory Number Theory Textbook, §3.3, original authored open textbook rendered by Mathematics LibreTexts. [^ref-0a8f46550a53]: Abhinav Kumar, MIT 18.781 Theory of Numbers, Lecture 4, Fermat corollary and proof. [^ref-df555e024ba4]: Abhinav Kumar, MIT 18.781 Theory of Numbers, Lecture 6, primality testing and Carmichael limitation.

Relationships to Other Abstractions

Local relationship map for Fermat's Little TheoremParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Fermat'sLittle TheoremDOMAINDomain-specific abstraction: Modular arithmetic — presupposesModulararithmeticDOMAIN

Current abstraction Fermat's Little Theorem Domain-specific

Parents (1) — more general patterns this builds on

  • Fermat's Little Theorem presupposes Modular arithmetic Domain-specific

    A prime-modulus power congruence presupposes modular arithmetic and adds the theorem's prime and base conditions.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Fermat's Little Theorem sits in a moderately populated region (48th percentile for distinctiveness): it has near-neighbors but no dense thicket of look-alikes.

Family — Number-Theoretic Properties & Tests (20 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-08