A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Fermat's Little Theorem

Graduate Depth 78 in the knowledge graph I know this Set as goal
36topics build on this
367prerequisites beneath it
See this on the map →
Properties of CongruencesGroup Definition and ExamplesCryptographic Applications: RSAEuler's Criterion+3 more
fermats-little-theorem prime-powers modular-exponentiation

Core Idea

If p is prime and gcd(a,p) = 1, then ap-1 ≡ 1 (mod p). This cornerstone result characterizes the exponent structure of multiplicative groups mod p and enables fast modular exponentiation in cryptography.

Explainer

You already know from congruence properties that modular arithmetic is self-consistent: if a ≡ b (mod p), then ak ≡ bk (mod p). Fermat's Little Theorem takes this arithmetic into the multiplicative structure: if p is prime and a is not divisible by p, then ap-1 ≡ 1 (mod p). The key intuition comes from examining the set of multiples {a, 2a, 3a, ..., (p-1)a} reduced mod p. Because p is prime and gcd(a, p) = 1, these p-1 values are all distinct and nonzero — they produce the set {1, 2, ..., p-1} in some scrambled order. So their product equals the product of all nonzero residues: a · 2a · 3a · ... · (p-1)a ≡ 1 · 2 · 3 · ... · (p-1) (mod p). Factoring out ap-1 from the left yields ap-1 · (p-1)! ≡ (p-1)! (mod p). Since (p-1)! is nonzero mod p, cancel it to get ap-1 ≡ 1 (mod p).

The theorem has a tidy corollary: for any integer a (not just those coprime to p), ap ≡ a (mod p). This form is often more convenient because no divisibility check is needed. Both forms appear throughout number theory and in computing.

The practical power is enormous. Modular exponentiation — the engine of RSA encryption — relies on reducing large exponents mod (p-1). For example, to compute 7100 mod 13: since 13 is prime, 712 ≡ 1 (mod 13). Write 100 = 8·12 + 4, so 7100 = (712)8 · 74 ≡ 18 · 74 ≡ 74 ≡ 2401 ≡ 9 (mod 13). Without Fermat's Little Theorem, this computation over cryptographic-scale numbers — hundreds of digits long — would be infeasible.

If you have encountered group theory, the result has a clean restatement: the nonzero residues mod p form a multiplicative group of order p-1. By Lagrange's theorem, every element's order divides the group order, so ap-1 = 1 for all elements a. Fermat's Little Theorem is Lagrange's theorem specialized to the group (Z/pZ)*. This group-theoretic view also explains why the exponent is p-1 specifically: it equals the size of the group, not an arbitrary bound.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesSet Operations: Union, Intersection, and ComplementProof by CasesProving by Cases and ExhaustionVacuous Truth and Trivial CasesProof by Cases (Proof by Exhaustion)Mathematical InductionDivisibility and Greatest Common DivisorThe Euclidean AlgorithmModular Arithmetic and CongruencesProperties of CongruencesFermat's Little Theorem

Longest path: 79 steps · 367 total prerequisite topics

Prerequisites (2)

Leads To (5)