Sub topic 11
Euler's Theorem for Composite Moduli
Prerequisites and the main idea
Assume you can factor integers, find greatest common divisors, and work with remainders. Euler's theorem extends Fermat's little theorem to many composite moduli.
Euler's theorem states:
If gcd(a, n) = 1, then
a^φ(n) ≡ 1 (mod n)
Here, φ(n), called Euler's totient, is the number of positive integers up to n that are relatively prime to n. Two numbers are relatively prime when their greatest common divisor is 1.
For a prime p, φ(p) = p − 1. Therefore, Euler's theorem becomes Fermat's little theorem for prime moduli. For a composite modulus, the exponent is usually φ(n), not n − 1.
Finding Euler's totient
If the prime factorisation of n is
n = p₁^e₁ × p₂^e₂ × ...,
then
φ(n) = n × (1 − 1/p₁) × (1 − 1/p₂) × ...
Each distinct prime factor appears once in the formula.
| Modulus | Prime factorisation | φ(n) |
|---|---|---|
| 12 | 2² × 3 | 12 × 1/2 × 2/3 = 4 |
| 20 | 2² × 5 | 20 × 1/2 × 4/5 = 8 |
| 36 | 2² × 3² | 36 × 1/2 × 2/3 = 12 |
For example, φ(20) = 8 because the numbers 1, 3, 7, 9, 11, 13, 17 and 19 are relatively prime to 20.
Worked example: a composite modulus
Find the remainder of 7²²² when divided by 20.
First check the condition:
gcd(7, 20) = 1
Now calculate the totient:
φ(20) = 8
Euler's theorem gives:
7⁸ ≡ 1 (mod 20)
Reduce the exponent modulo 8:
222 = 8 × 27 + 6
Therefore,
7²²² ≡ 7⁶ (mod 20)
Continue with small powers:
7² = 49 ≡ 9 (mod 20)
7⁴ ≡ 9² = 81 ≡ 1 (mod 20)
7⁶ ≡ 7⁴ × 7² ≡ 1 × 9 ≡ 9 (mod 20)
The remainder is 9.
print(pow(7, 222, 20)) # 9The condition that is often missed
You may use Euler's theorem only when gcd(a, n) = 1. For example, gcd(6, 15) = 3, so Euler's theorem cannot directly simplify 6^k modulo 15.
This does not mean the problem cannot be solved. Try repeated reduction, factorisation, or the Chinese Remainder Theorem instead. Applying φ(15) = 8 and claiming 6⁸ ≡ 1 (mod 15) would be incorrect. In fact, 6² ≡ 6 (mod 15), so every positive power of 6 has remainder 6.
CAT decision process
Under time pressure, factor the modulus first if it is small. If the base and modulus are coprime, compute φ(n), reduce the exponent, and then use the shortest remaining calculation.
Exercise
Find the remainder of 3^100 modulo 40.
Show answer
gcd(3, 40) = 1 and φ(40) = 16. Since 100 ≡ 4 (mod 16), 3^100 ≡ 3^4 = 81 ≡ 1 (mod 40). The remainder is 1.