Number System

Fermat’s Little Theorem

A pupil follows a repeating pattern around a ring.

Fermat’s Little Theorem definition

Fermat’s little theorem says that if p is prime and p does not divide a, then a^(p − 1) ≡ 1 (mod p).

In Spanish
pequeño teorema de Fermat
Topic
Number theory

Fermat’s Little Theorem in a picture

Fermat’s Little Theorem diagramUse the prime modulus to reduce the power in blocks of p − 1.Prime modulus p = 7The base 3 is not divisible by 73⁶ ≡ 1 (mod 7)Apply the theorem3⁸ ≡ 3² ≡ 2 (mod 7)Reduce the exponent
Use the prime modulus to reduce the power in blocks of p − 1.

How it works

An equivalent form is aᵖ ≡ a (mod p) for every integer a. The theorem helps reduce large powers modulo a prime. A composite modulus can sometimes satisfy the same congruence for a chosen base, so passing a Fermat test does not prove primality in general.

Worked examples

Find 2⁶ modulo 7.

1, by the theorem.

Find 2¹⁰ modulo 7.

2⁶ ≡ 1, so 2¹⁰ ≡ 2⁴ ≡ 2.

Does a ≡ 0 (mod p) satisfy a^(p − 1) ≡ 1?

No. The condition excludes bases divisible by p.

Common mistake

Verify that the modulus is prime and that the base is coprime to it before using the first form.

Quick check

What must p be?

Show answer

Prime.

What power has remainder 1 when p does not divide a?

Show answer

The (p − 1)st power.

Does the theorem work as a complete proof of primality?

Show answer

No. Some composites pass a Fermat test for particular bases.

Sources

Flashcard

Fermat’s Little Theorem

Reveal the definition

Fermat’s little theorem says that if p is prime and p does not divide a, then a^(p − 1) ≡ 1 (mod p).

Effortless Math. “Fermat’s Little Theorem.” Math Dictionary.