2.5.11 · D3Number Theory (Intermediate)

Worked examples — Fermat's little theorem (statement)

2,318 words11 min readBack to topic

This page is the "throw everything at it" companion to Fermat's little theorem (statement). The parent gave you the statement; here we drill through every kind of situation the theorem can be dropped into, so that when an exam or a real computation hands you a strange-looking case, you have already seen its cousin.

Before we start, a one-line refresher of the only two facts we lean on. If is a prime (a whole number bigger than 1 whose only divisors are 1 and itself) and is coprime to (they share no factor bigger than 1, written ), then

and for any integer at all,

The notation just means " and leave the same remainder when divided by " — think of a clock with hours. If that clock idea is fuzzy, revisit Modular Arithmetic Basics first.


The scenario matrix

Every problem you can be handed with this theorem falls into one of these cells. The worked examples below are labelled with the cell they hit, and together they cover all of them.

Cell What makes it that case Covered by
A. Direct check small , coprime — just verify Example 1
B. Huge exponent reduce exponent using Example 2
C. (reduce base first) base bigger than modulus Example 3
D. (degenerate) is a multiple of Example 4
E. Negative base Example 5
F. Modular inverse use Example 6
G. Non-prime modulus (trap) composite — theorem fails Example 7
H. Real-world word problem RSA-flavoured decryption Example 8
I. Exam twist exponent as a tower / mixed forms Example 9

The worked examples


Figure — Fermat's little theorem (statement)

The figure above shows the "reset clock" idea that every example above relies on: powers of march around the residues and land back on 1 exactly every steps.


Recall Which cell is which?

Answer needs which trick? ::: Cell B — reduce the exponent mod . Why does instead of 1? ::: Cell D — , coprimality fails. For , why can't we use FLT? ::: Cell G — is composite; use instead. To find , which power do we compute? ::: (Cell F). In we reduce the exponent by which number? ::: By , not by 7 (Cell I).

Connections

  • Fermat's little theorem (statement) — the parent statement this page drills.
  • Modular Arithmetic Basics — the clock arithmetic behind every reduction.
  • Euler's Totient Function — repairs Cells D and G (composite / non-coprime).
  • Multiplicative Group Modulo Prime — why the reset point is exactly .
  • Modular Exponentiation Algorithms — the fast-squaring used in Examples 7–9.
  • RSA Cryptosystem — the real-world Cell H application.
  • Carmichael Numbers — composites that mimic the prime pattern.
  • Properties of Prime Numbers — why primality is non-negotiable.