Euler’s Theorem

Chapter 7: Number Theory

Learning objectives

  • Define Euler’s totient ϕ(n)\phi(n)
  • Compute ϕ(n)\phi(n) for prime powers and via multiplicativity
  • State and apply Euler’s theorem: aϕ(n)1(modn)a^{\phi(n)} \equiv 1 \pmod{n} when gcd(a,n)=1\gcd(a, n) = 1
  • Derive Fermat’s little theorem as the prime-modulus special case

Euler’s theorem is the engine inside RSA. It says: if you live in Z/nZ\mathbb{Z}/n\mathbb{Z} and you are coprime to nn, then raising yourself to the power ϕ(n)\phi(n) lands you exactly back on 11. That single identity — first proved by Euler in 1763 — is what makes RSA decryption work: the recipient’s private exponent dd is chosen so that ed1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}, and Euler’s theorem then guarantees (me)dm(modn)(m^e)^d \equiv m \pmod{n}. Beyond RSA, Euler’s theorem powers pseudo-random number generators, primality tests, and the entire theory of finite cyclic groups.

Euler’s totient ϕ(n)\phi(n)

The Euler totient ϕ(n)\phi(n) counts the integers kk with 1kn1 \leq k \leq n and gcd(k,n)=1\gcd(k, n) = 1. These are exactly the units of Z/nZ\mathbb{Z}/n\mathbb{Z} — the elements that have multiplicative inverses. Examples: ϕ(1)=1\phi(1) = 1, ϕ(5)=4\phi(5) = 4 (namely 1,2,3,41, 2, 3, 4), ϕ(12)=4\phi(12) = 4 (namely 1,5,7,111, 5, 7, 11).

Computing ϕ\phi from the prime factorisation. ϕ\phi is multiplicative: if gcd(m,n)=1\gcd(m, n) = 1, then ϕ(mn)=ϕ(m)ϕ(n)\phi(mn) = \phi(m) \phi(n). Combined with ϕ(pk)=pkpk1=pk1(p1)\phi(p^k) = p^k - p^{k-1} = p^{k-1}(p - 1) for prime pp, this gives a formula for every nn: factor n=p1a1prarn = p_1^{a_1} \cdots p_r^{a_r} and compute ϕ(n)=ipiai1(pi1)\phi(n) = \prod_i p_i^{a_i - 1}(p_i - 1). Example: ϕ(360)=ϕ(23325)=464=96\phi(360) = \phi(2^3 \cdot 3^2 \cdot 5) = 4 \cdot 6 \cdot 4 = 96.

The group (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times

The set UnU_n of units of Z/nZ\mathbb{Z}/n\mathbb{Z} is closed under multiplication: if a,ba, b are both coprime to nn, so is abab. It contains 11, and every unit has an inverse (that is the definition). So UnU_n is a finite abelian group of order ϕ(n)\phi(n), often written (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times. The mapping below illustrates how multiplication-by-a fixed unit aa permutes UnU_n:

Mapping ArrowsInteractive figure — enable JavaScript to interact.

(The mapping-arrows widget visualises a function between two sets. Mentally label the left column with the units of Z/nZ\mathbb{Z}/n\mathbb{Z} and the right column with the same set; an arrow from xx to axmodna \cdot x \bmod n shows multiplication-by-aa as a permutation. Because aa is a unit, every element on the right is hit exactly once.)

Euler’s theorem

If gcd(a,n)=1\gcd(a, n) = 1, then aϕ(n)1(modn)a^{\phi(n)} \equiv 1 \pmod{n}.

Sketch of proof. Let r1,r2,,rϕ(n)r_1, r_2, \ldots, r_{\phi(n)} be the units of Z/nZ\mathbb{Z}/n\mathbb{Z}. Multiplication by aa permutes them (because aa is a unit). So {ar1,ar2,,arϕ(n)}={r1,r2,,rϕ(n)}{a r_1, a r_2, \ldots, a r_{\phi(n)}} = {r_1, r_2, \ldots, r_{\phi(n)}} as sets. Take the product of both sides: aϕ(n)riri(modn)a^{\phi(n)} \cdot \prod r_i \equiv \prod r_i \pmod{n}. The product ri\prod r_i is itself a unit, so we may cancel it: aϕ(n)1(modn)a^{\phi(n)} \equiv 1 \pmod{n}.

Fermat’s little theorem — the special case n=pn = p

When n=pn = p is prime, ϕ(p)=p1\phi(p) = p - 1. Euler’s theorem becomes: if pap \nmid a, then ap11(modp)a^{p-1} \equiv 1 \pmod{p}. Equivalently, apa(modp)a^p \equiv a \pmod{p} for all integers aa (just multiply by aa if pap \mid a). This is Fermat’s little theorem, the prototype primality-test: pick a random aa, compute an1modna^{n-1} \bmod n, and if you get anything other than 11, nn is definitely composite.

Pause and think: Why does Euler’s theorem require gcd(a,n)=1\gcd(a, n) = 1? Consider what goes wrong with a=2,n=4a = 2, n = 4: compute 2ϕ(4)=22mod42^{\phi(4)} = 2^2 \bmod 4 directly. The result is not 11. The proof breaks because multiplication-by-22 does not permute the units of Z/4Z\mathbb{Z}/4\mathbb{Z}.

Try it

  • Predict ϕ(15)\phi(15) before computing. Then enumerate the integers 1k151 \leq k \leq 15 with gcd(k,15)=1\gcd(k, 15) = 1 and confirm.
  • Use Euler’s theorem to compute 740mod1007^{40} \bmod 100 without ever forming 7407^{40}. (Hint: ϕ(100)=40\phi(100) = 40.)
  • Compute 330mod73^{30} \bmod 7 via Fermat’s little theorem.
  • Show that ϕ(pq)=(p1)(q1)\phi(p \cdot q) = (p - 1)(q - 1) when p,qp, q are distinct primes. (This is the formula RSA uses.)

A trap to watch for

The two formulas ϕ(p)=p1\phi(p) = p - 1 and ϕ(pk)=pkpk1\phi(p^k) = p^k - p^{k-1} look similar but behave very differently. For a prime pp, almost every residue is coprime — only 00 is not. For a prime power pkp^k, the coprime residues miss every multiple of pp, so the density of units drops to (p1)/p(p-1)/p. A common mistake is to assume ϕ(pk)=pk1\phi(p^k) = p^k - 1 by analogy — that would only be correct if pkp^k were itself prime, which it isn’t for k2k \geq 2. Always factor first, then apply the totient formula prime-by-prime.

Code ChallengeInteractive figure — enable JavaScript to interact.

What you now know

You can compute ϕ(n)\phi(n) from the prime factorisation, apply Euler’s theorem to collapse huge powers into single residues, and recognise Fermat’s little theorem as the n=pn = p special case. In the final section, public-key cryptography, you will see how RSA stitches Euler’s theorem and the hardness of factoring into a working encryption scheme.

References

  • Velleman, D. J. (2019). How to Prove It: A Structured Approach (3rd ed.). Cambridge University Press, §7.4.
  • Hardy, G. H., Wright, E. M. (2008). An Introduction to the Theory of Numbers (6th ed.). Oxford University Press, ch. 5–6.
  • Niven, I., Zuckerman, H. S., Montgomery, H. L. (1991). An Introduction to the Theory of Numbers (5th ed.). Wiley, ch. 2.
  • Rosen, K. H. (2010). Elementary Number Theory (6th ed.). Pearson, ch. 6.
  • Koblitz, N. (1994). A Course in Number Theory and Cryptography (2nd ed.). Springer, ch. 1.

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.