φ(m) counts the units
The integers in 1, …, m coprime to m. They are exactly the invertible elements of ℤ_m, by “Bézout's Identity and Modular Inverses”.
a^{φ(m)} ≡ 1 (mod m) when gcd(a,m) = 1, with Fermat's a^{p−1} ≡ 1 the prime case. It collapses enormous exponents and it is the theorem that makes RSA decryption work.
Core ideas
One theorem, two names, and the single most useful computational fact in the course.
The integers in 1, …, m coprime to m. They are exactly the invertible elements of ℤ_m, by “Bézout's Identity and Modular Inverses”.
Not modulo m. 7^100 mod 10 becomes 7^{100 mod 4} = 7^0 = 1, because φ(10) = 4.
2^{φ(4)} = 2² = 4 ≡ 0 (mod 4), not 1. The theorem says nothing about bases sharing a factor with the modulus.
The material
The totient, both theorems, the proof, and the consequences.
φ(m) is the number of integers in {1, …, m} coprime to m. φ(1) = 1.
φ(p) = p − 1 for prime p; φ(p^k) = p^k − p^{k−1}; and φ is multiplicative on coprime arguments, so φ(mn) = φ(m)φ(n) when gcd(m,n) = 1. In general φ(n) = n Π_{p | n} (1 − 1/p).
The multiplicativity is the Chinese remainder theorem in disguise: ℤ_{mn} ≅ ℤ_m × ℤ_n for coprime moduli, and an element is invertible in the product exactly when both components are. The product formula is inclusion and exclusion over the prime divisors, from “The Inclusion-Exclusion Principle” in Combinatorics and Counting.
If gcd(a, m) = 1 then a^{φ(m)} ≡ 1 (mod m).
Let u₁, …, u_φ be the units modulo m — the residues coprime to m. Multiplying each by a gives au₁, …, au_φ, which are again units (a product of units is a unit) and are distinct, since a is invertible and cancellation holds for units.
So {au₁, …, au_φ} is the same set as {u₁, …, u_φ} modulo m, and their products agree: a^φ · (u₁⋯u_φ) ≡ u₁⋯u_φ (mod m).
The product of the units is itself a unit, so it may be cancelled, leaving a^{φ(m)} ≡ 1.
□
If p is prime and p ∤ a then a^{p−1} ≡ 1 (mod p). Equivalently, a^p ≡ a (mod p) for every a.
This is Euler with m = p, since φ(p) = p − 1. The second form holds even when p | a, because both sides are then 0.
If gcd(a,m) = 1 then a^k ≡ a^{k mod φ(m)} (mod m).
7^{1000} mod 13. φ(13) = 12 and 1000 = 83·12 + 4, so 7^{1000} ≡ 7⁴ (mod 13). And 7² = 49 ≡ 10, 7⁴ ≡ 100 ≡ 9. The answer is 9, from two multiplications.
Combined with “Modular Exponentiation”'s fast exponentiation this makes essentially any modular power computable: reduce the exponent by φ(m) first, then square and multiply.
Fermat's theorem gives a test: if a^{n−1} ≢ 1 (mod n) for some a coprime to n, then n is definitely composite. The converse fails — Carmichael numbers such as 561 pass for every coprime base while being composite — which is why the Miller–Rabin refinement is used in practice.
This is what makes RSA key generation possible: random 1024-bit numbers are tested until one passes, and about one in 700 does. Nothing factorises anything.
Interactive
Algorithms with their traces
Method
Check coprimality, compute φ, reduce the exponent.
Without it neither theorem applies. The powers of a non-coprime base never return to 1.
From the factorisation of m, using multiplicativity and φ(p^k) = p^k − p^{k−1}.
a^k ≡ a^{k mod φ(m)}. This is the step that turns an impossible computation into a small one.
By square and multiply if it is still large. Usually it is trivial.
An exponent with seven digits, reduced to one.
Two facts made this possible: Euler reduced the exponent from 1 234 567 to 7, and modular reduction kept every intermediate below 10 000. Either alone would have been insufficient.
Compute 2^{1000000} mod 77. φ(77) = 60, so the exponent becomes 1000000 mod 60 = 40, and 2^40 mod 77 is a short square-and-multiply.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.