Euler's Theorem

Contents

This note continues the Fermat’s Little Theorem note, whose reduced residue systems and multiplicative orders it uses throughout. As before, all variables are integers unless otherwise specified, and the modulus mm is always a positive integer.

Euler’s Phi Function

Definition 15 (Euler's Phi Function).

For every m∈Nm \in \bbN, φ(m)\varphi(m) is defined as the number of elements in any reduced residue system modulo mm. Symbolically,

φ(m)=∣{a∈Z ⁣:0≤a≤m−1 and gcd⁡(a,m)=1}∣.\varphi(m) = \left\lvert \left\{ a \in \bbZ \colon 0 \leq a \leq m - 1 \text{ and } \gcd(a, m) = 1 \right\} \right\rvert.

As noted in Complete and Reduced Residue Systems of the Fermat’s Little Theorem note, all reduced residue systems modulo mm have the same size, so φ(m)\varphi(m) is well defined. For example, {1,3,7,9}\{ 1, 3, 7, 9 \} is a reduced residue system modulo 1010, so φ(10)=4\varphi(10) = 4. For any prime pp, {1,2,…,p−1}\{ 1, 2, \ldots, p - 1 \} is a reduced residue system modulo pp, so φ(p)=p−1\varphi(p) = p - 1. Also φ(1)=1\varphi(1) = 1, since gcd⁡(0,1)=1\gcd(0, 1) = 1.

Proposition 16.

For any prime pp and positive integer α\alpha,

φ(pα)=pα−pα−1.\varphi\left(p^\alpha\right) = p^\alpha - p^{\alpha - 1}.
Proof.

An integer is coprime to pαp^\alpha if and only if it is not divisible by pp. Among the pαp^\alpha integers 0,1,…,pα−10, 1, \ldots, p^\alpha - 1, the multiples of pp are 0,p,2p,…,(pα−1−1)p0, p, 2p, \ldots, \left(p^{\alpha - 1} - 1\right)p, and there are pα−1p^{\alpha - 1} of them. The remaining pα−pα−1p^\alpha - p^{\alpha - 1} integers are coprime to pαp^\alpha.

For example, φ(8)=8−4=4\varphi(8) = 8 - 4 = 4 (the reduced residues are 1,3,5,71, 3, 5, 7) and φ(9)=9−3=6\varphi(9) = 9 - 3 = 6.

Proposition 17.

Euler’s phi function is multiplicative: if gcd⁡(m,n)=1\gcd(m, n) = 1, then φ(mn)=φ(m)φ(n)\varphi(mn) = \varphi(m) \varphi(n).

Proof sketch.

By the Chinese Remainder Theorem (Theorem 16 of the Congruence note), each x∈{0,1,…,mn−1}x \in \{ 0, 1, \ldots, mn - 1 \} corresponds to exactly one pair (x mod m, x mod n)(x \bmod m,\, x \bmod n), and every pair occurs. Now gcd⁡(x,mn)=1\gcd(x, mn) = 1 if and only if gcd⁡(x,m)=1\gcd(x, m) = 1 and gcd⁡(x,n)=1\gcd(x, n) = 1 (by Proposition 3 of the Fermat’s Little Theorem note for one direction; any common prime factor of xx and mm or nn also divides mnmn for the other). Moreover, gcd⁡(x,m)=gcd⁡(x mod m,m)\gcd(x, m) = \gcd(x \bmod m, m), since xx and x mod mx \bmod m differ by a multiple of mm. Hence xx is coprime to mnmn exactly when x mod mx \bmod m is one of the φ(m)\varphi(m) reduced residues modulo mm and x mod nx \bmod n is one of the φ(n)\varphi(n) reduced residues modulo nn. There are φ(m)φ(n)\varphi(m) \varphi(n) such pairs.

For example, φ(10)=φ(2)φ(5)=1×4=4\varphi(10) = \varphi(2) \varphi(5) = 1 \times 4 = 4, matching the reduced residue system {1,3,7,9}\{ 1, 3, 7, 9 \}. Combining the two propositions above with the prime factorization gives a formula for φ(n)\varphi(n).

Proposition 18.

Suppose n∈Nn \in \bbN has the prime factorization

n=p1α1p2α2⋯pkαk,n = p_1^{\alpha_1} p_2^{\alpha_2} \cdots p_k^{\alpha_k},

where p1,p2,…,pkp_1, p_2, \ldots, p_k are distinct primes and α1,α2,…,αk\alpha_1, \alpha_2, \ldots, \alpha_k are positive integers. Then

φ(n)=(p1α1−p1α1−1)(p2α2−p2α2−1)⋯(pkαk−pkαk−1).\varphi(n) = \left( p_1^{\alpha_1} - p_1^{\alpha_1 - 1} \right) \left( p_2^{\alpha_2} - p_2^{\alpha_2 - 1} \right) \cdots \left( p_k^{\alpha_k} - p_k^{\alpha_k - 1} \right).

Equivalently,

φ(n)=n(1−1p1)(1−1p2)⋯(1−1pk).\varphi(n) = n \left( 1 - \frac{1}{p_1} \right) \left( 1 - \frac{1}{p_2} \right) \cdots \left( 1 - \frac{1}{p_k} \right).
Proof.

The prime powers p1α1,p2α2,…,pkαkp_1^{\alpha_1}, p_2^{\alpha_2}, \ldots, p_k^{\alpha_k} are pairwise coprime, so repeated application of Proposition 17 gives φ(n)=φ(p1α1)φ(p2α2)⋯φ(pkαk)\varphi(n) = \varphi\left(p_1^{\alpha_1}\right) \varphi\left(p_2^{\alpha_2}\right) \cdots \varphi\left(p_k^{\alpha_k}\right). Now apply Proposition 16 to each factor. The second form follows from pα−pα−1=pα(1−1p)p^\alpha - p^{\alpha - 1} = p^\alpha \left( 1 - \frac{1}{p} \right).

Example 19.

Since 100=22×52100 = 2^2 \times 5^2,

φ(100)=(22−2)(52−5)=2×20=40.\varphi(100) = \left(2^2 - 2\right)\left(5^2 - 5\right) = 2 \times 20 = 40.

Equivalently, φ(100)=100(1−12)(1−15)=40\varphi(100) = 100 \left(1 - \frac{1}{2}\right)\left(1 - \frac{1}{5}\right) = 40. So exactly 4040 of the integers 1,2,…,1001, 2, \ldots, 100 are coprime to 100100.

Exercise 20.

Compute φ(12)\varphi(12), φ(30)\varphi(30), φ(81)\varphi(81), and φ(1000)\varphi(1000).

Answer

φ(12)=φ(4)φ(3)=2×2=4\varphi(12) = \varphi(4)\varphi(3) = 2 \times 2 = 4; φ(30)=φ(2)φ(3)φ(5)=1×2×4=8\varphi(30) = \varphi(2)\varphi(3)\varphi(5) = 1 \times 2 \times 4 = 8; φ(81)=81−27=54\varphi(81) = 81 - 27 = 54; φ(1000)=1000(1−12)(1−15)=400\varphi(1000) = 1000 \left(1 - \frac{1}{2}\right)\left(1 - \frac{1}{5}\right) = 400.

Euler’s Theorem

Euler’s Theorem generalizes Fermat’s Little Theorem from a prime modulus to an arbitrary modulus.

Theorem 21 (Euler's Theorem).

For any a∈Za \in \bbZ and m∈Nm \in \bbN with gcd⁡(a,m)=1\gcd(a, m) = 1, we have

aφ(m)≡1(modm).a^{\varphi(m)} \equiv 1 \pmod{m}.

In other words, by Proposition 8 of the Fermat’s Little Theorem note, ord⁡m(a)∣φ(m)\ord_m(a) \divides \varphi(m).

Proof.

The argument is the same as for Fermat’s Little Theorem, with an arbitrary reduced residue system in place of {1,2,…,p−1}\{ 1, 2, \ldots, p - 1 \}. Let T={r1,r2,…,rk}T = \{ r_1, r_2, \ldots, r_k \} be a reduced residue system modulo mm, where k=φ(m)k = \varphi(m). By Lemma 5 of the Fermat’s Little Theorem note,

r1r2⋯rk≡aφ(m) r1r2⋯rk(modm).r_1 r_2 \cdots r_k \equiv a^{\varphi(m)} \, r_1 r_2 \cdots r_k \pmod{m}.

By Proposition 3, gcd⁡(r1r2⋯rk,m)=1\gcd(r_1 r_2 \cdots r_k, m) = 1, so the Cancellation Law gives aφ(m)≡1(modm)a^{\varphi(m)} \equiv 1 \pmod{m}.

When m=pm = p is prime, φ(p)=p−1\varphi(p) = p - 1, and Euler’s Theorem becomes Fermat’s Little Theorem. When m=10m = 10, φ(10)=4\varphi(10) = 4, and Euler’s Theorem says a4≡1(mod10)a^4 \equiv 1 \pmod{10} for every aa coprime to 1010; this explains why the units digits of powers of 11, 33, 77, 99 repeat with period dividing 44 (compare Example 7 of the Fermat’s Little Theorem note).

Example 22.

Find the last two digits of 320263^{2026}.

Solution

We work modulo 100100. Since gcd⁡(3,100)=1\gcd(3, 100) = 1 and φ(100)=40\varphi(100) = 40 by Example 19, Euler’s Theorem gives 340≡1(mod100)3^{40} \equiv 1 \pmod{100}. Since 2026=40×50+262026 = 40 \times 50 + 26,

32026=(340)50×326≡326(mod100).3^{2026} = \left(3^{40}\right)^{50} \times 3^{26} \equiv 3^{26} \pmod{100}.

Now 35=243≡433^5 = 243 \equiv 43, 310≡432=1849≡493^{10} \equiv 43^2 = 1849 \equiv 49, and 320≡492=2401≡1(mod100)3^{20} \equiv 49^2 = 2401 \equiv 1 \pmod{100}. Therefore 326=320×36≡729≡29(mod100)3^{26} = 3^{20} \times 3^6 \equiv 729 \equiv 29 \pmod{100}, and the last two digits are 2929.

Remark. The computation shows more: since 320≡1(mod100)3^{20} \equiv 1 \pmod{100}, while 320/2=310≡493^{20/2} = 3^{10} \equiv 49 and 320/5=34=813^{20/5} = 3^4 = 81 are not ≡1(mod100)\equiv 1 \pmod{100}, the remark after Proposition 8 of the Fermat’s Little Theorem note gives ord⁡100(3)=20\ord_{100}(3) = 20, a proper divisor of φ(100)=40\varphi(100) = 40. Euler’s Theorem gives an exponent that works, but not necessarily the smallest one. On the AMC, it is often fastest to compute a few powers directly and look for the cycle.

Exercise 23.

Find the last two digits of 720267^{2026}.

Hint: Compute 747^4.

Exercise 24.

Find the remainder when 51005^{100} is divided by 3636.

Answers

23. By Euler’s Theorem, 740≡1(mod100)7^{40} \equiv 1 \pmod{100}, but in fact 74=2401≡1(mod100)7^4 = 2401 \equiv 1 \pmod{100}. Since also 72=49≢1(mod100)7^2 = 49 \not\equiv 1 \pmod{100}, we get ord⁡100(7)=4\ord_{100}(7) = 4. Since 2026=4×506+22026 = 4 \times 506 + 2, we get 72026≡72=49(mod100)7^{2026} \equiv 7^2 = 49 \pmod{100}. The last two digits are 4949.

24. φ(36)=φ(4)φ(9)=2×6=12\varphi(36) = \varphi(4)\varphi(9) = 2 \times 6 = 12 and gcd⁡(5,36)=1\gcd(5, 36) = 1, so 512≡1(mod36)5^{12} \equiv 1 \pmod{36}. Since 100=12×8+4100 = 12 \times 8 + 4, we get 5100≡54=625=17×36+13≡13(mod36)5^{100} \equiv 5^4 = 625 = 17 \times 36 + 13 \equiv 13 \pmod{36}. The remainder is 1313.

Application: Repeating Decimals

The multiplicative order also explains the length of the repeating block in decimals such as

17=0.142857‾=0.142857 142857 142857…\frac{1}{7} = 0.\overline{142857} = 0.142857\,142857\,142857\ldots

Proposition 25.

Let n>1n > 1 with gcd⁡(n,10)=1\gcd(n, 10) = 1. Then the decimal expansion of 1n\frac{1}{n} is purely periodic, and the length of its shortest repeating block is ord⁡n(10)\ord_n(10). In particular, this length divides φ(n)\varphi(n).

Proof.

Suppose 10k≡1(modn)10^k \equiv 1 \pmod{n} for some positive integer kk, and write 10k−1=nA10^k - 1 = nA. Since n>1n > 1, we have 0<A<10k0 < A < 10^k, and

1n=A10k−1=A10k⋅11−10−k=A10k+A102k+A103k+⋯ ,\frac{1}{n} = \frac{A}{10^k - 1} = \frac{A}{10^k} \cdot \frac{1}{1 - 10^{-k}} = \frac{A}{10^k} + \frac{A}{10^{2k}} + \frac{A}{10^{3k}} + \cdots,

so the decimal expansion of 1n\frac{1}{n} repeats the kk digits of AA (padded with leading zeros if necessary). By Euler’s Theorem such a kk exists, so the expansion is purely periodic, and taking k=ord⁡n(10)k = \ord_n(10) gives a repeating block of length ord⁡n(10)\ord_n(10).

Conversely, suppose the expansion repeats with a block of length kk. Moving the decimal point kk places to the right, 10kn\frac{10^k}{n} has the same digits after the decimal point as 1n\frac{1}{n}, so 10k−1n\frac{10^k - 1}{n} is an integer. Thus 10k≡1(modn)10^k \equiv 1 \pmod{n}, and hence k≥ord⁡n(10)k \geq \ord_n(10). The last statement follows from Euler’s Theorem.

Example 26.

Since 10≡3(mod7)10 \equiv 3 \pmod{7} and ord⁡7(3)=6\ord_7(3) = 6 (Exercise 13 of the Fermat’s Little Theorem note), the repeating block of 17\frac{1}{7} has length 66. Indeed, 106−1=999999=7×14285710^6 - 1 = 999999 = 7 \times 142857.

For n=13n = 13, we have 102=100≡910^2 = 100 \equiv 9 and 103≡90≡−1(mod13)10^3 \equiv 90 \equiv -1 \pmod{13}, so 106≡1(mod13)10^6 \equiv 1 \pmod{13}, while 106/2≢110^{6/2} \not\equiv 1 and 106/3≢110^{6/3} \not\equiv 1. Hence ord⁡13(10)=6\ord_{13}(10) = 6, and indeed 113=0.076923‾\frac{1}{13} = 0.\overline{076923}, since 999999=13×76923999999 = 13 \times 76923.

Exercise 27.

Find the length of the repeating block of 137\frac{1}{37} and of 141\frac{1}{41}.

Answer

Since 103−1=999=27×3710^3 - 1 = 999 = 27 \times 37 and 10≢1(mod37)10 \not\equiv 1 \pmod{37}, we get ord⁡37(10)=3\ord_{37}(10) = 3, and 137=0.027‾\frac{1}{37} = 0.\overline{027}. Since 105−1=99999=41×243910^5 - 1 = 99999 = 41 \times 2439, 55 is prime, and 10≢1(mod41)10 \not\equiv 1 \pmod{41}, we get ord⁡41(10)=5\ord_{41}(10) = 5, and 141=0.02439‾\frac{1}{41} = 0.\overline{02439}.

Last Two Digits and the Chinese Remainder Theorem

Euler’s Theorem requires gcd⁡(a,m)=1\gcd(a, m) = 1, so it does not directly give the last two digits of a power of 22 or 55. In such cases, split 100=4×25100 = 4 \times 25 with gcd⁡(4,25)=1\gcd(4, 25) = 1, work modulo 44 and modulo 2525 separately, and recombine with the Chinese Remainder Theorem (Theorem 16 of the Congruence note).

Example 28.

Find the last two digits of 220262^{2026}.

Solution

Modulo 44: since 22=42^2 = 4, we have 22026≡0(mod4)2^{2026} \equiv 0 \pmod{4}. Modulo 2525: since gcd⁡(2,25)=1\gcd(2, 25) = 1 and φ(25)=25−5=20\varphi(25) = 25 - 5 = 20, Euler’s Theorem gives 220≡1(mod25)2^{20} \equiv 1 \pmod{25}. Since 2026=20×101+62026 = 20 \times 101 + 6, we get 22026≡26=64≡14(mod25)2^{2026} \equiv 2^6 = 64 \equiv 14 \pmod{25}. The numbers below 100100 that are ≡14(mod25)\equiv 14 \pmod{25} are 14,39,64,8914, 39, 64, 89, and only 6464 is divisible by 44. Therefore 22026≡64(mod100)2^{2026} \equiv 64 \pmod{100}, and the last two digits are 6464.

Splitting 100=4×25100 = 4 \times 25 helps even when gcd⁡(a,10)=1\gcd(a, 10) = 1. In that case aa is odd, so a2≡1(mod4)a^2 \equiv 1 \pmod{4} (since φ(4)=2\varphi(4) = 2), and a20≡1(mod25)a^{20} \equiv 1 \pmod{25} by Euler’s Theorem. Hence 44 and 2525 both divide a20−1a^{20} - 1, and since they are coprime,

a20≡1(mod100)for every a with gcd⁡(a,10)=1.a^{20} \equiv 1 \pmod{100} \qquad \text{for every } a \text{ with } \gcd(a, 10) = 1.

So the exponent 2020 works in place of φ(100)=40\varphi(100) = 40. This explains why ord⁡100(3)=20\ord_{100}(3) = 20 and ord⁡100(7)=4\ord_{100}(7) = 4 (Example 22 and Exercise 23) both divide 2020.

Power Towers

A power tower abca^{b^c} means a(bc)a^{\left(b^c\right)}. To find it modulo mm, work from the top down: if ak≡1(modm)a^k \equiv 1 \pmod{m}, then aN≡aN mod k(modm)a^N \equiv a^{N \bmod k} \pmod{m}, so it suffices to find the exponent N=bcN = b^c modulo the smaller number kk.

Example 29.

Find the last two digits of 3320263^{3^{2026}}.

Solution

Let N=32026N = 3^{2026}. Since 320≡1(mod100)3^{20} \equiv 1 \pmod{100}, we need N mod 20N \bmod 20. Now 34=81≡1(mod20)3^4 = 81 \equiv 1 \pmod{20} and 2026=4×506+22026 = 4 \times 506 + 2, so N≡32=9(mod20)N \equiv 3^2 = 9 \pmod{20}. Therefore

332026=3N≡39=19683≡83(mod100),3^{3^{2026}} = 3^N \equiv 3^9 = 19683 \equiv 83 \pmod{100},

and the last two digits are 8383. The moduli shrink at each level of the tower: 100100, then 2020, then 44.

Exercise 30.

Find the last two digits of 7777^{7^7}.

Answer

Since 74≡1(mod100)7^4 \equiv 1 \pmod{100}, we need 77 mod 47^7 \bmod 4. As 7≡−1(mod4)7 \equiv -1 \pmod{4}, we get 77≡−1≡3(mod4)7^7 \equiv -1 \equiv 3 \pmod{4}. Therefore 777≡73=343≡43(mod100)7^{7^7} \equiv 7^3 = 343 \equiv 43 \pmod{100}, and the last two digits are 4343.

Practice Problems

  1. For how many integers kk with 1≤k≤3601 \leq k \leq 360 is the fraction k360\frac{k}{360} in lowest terms?

    (A) 72(B) 90(C) 96(D) 120(E) 144\textup{(A)}\ 72 \qquad \textup{(B)}\ 90 \qquad \textup{(C)}\ 96 \qquad \textup{(D)}\ 120 \qquad \textup{(E)}\ 144
  2. 2011 AMC 8, Problem 22
  3. 2008 AMC 10A, Problem 24
  4. 1983 AIME, Problem 6

Solutions

Problem 1

(C) 96. The fraction k360\frac{k}{360} is in lowest terms exactly when gcd⁡(k,360)=1\gcd(k, 360) = 1. Since 360≡0(mod360)360 \equiv 0 \pmod{360}, the integers 1,2,…,3601, 2, \ldots, 360 form a complete residue system modulo 360360, so the count is φ(360)\varphi(360). As 360=23×32×5360 = 2^3 \times 3^2 \times 5,

φ(360)=360(1−12)(1−13)(1−15)=96.\varphi(360) = 360 \left(1 - \frac{1}{2}\right)\left(1 - \frac{1}{3}\right)\left(1 - \frac{1}{5}\right) = 96.
Problem 2

(D) 4. We find the last two digits. As in Exercise 23, 74=2401≡1(mod100)7^4 = 2401 \equiv 1 \pmod{100}. Since 2011=4×502+32011 = 4 \times 502 + 3, we get 72011≡73=343≡43(mod100)7^{2011} \equiv 7^3 = 343 \equiv 43 \pmod{100}. The tens digit is 44.

Problem 3

(D) 6. We work modulo 10=2×510 = 2 \times 5, using the Chinese Remainder Theorem as in Example 28. First, 20082≡82=64≡4(mod10)2008^2 \equiv 8^2 = 64 \equiv 4 \pmod{10}, and 22008≡6(mod10)2^{2008} \equiv 6 \pmod{10}, since 220082^{2008} is even and 22008=(24)502≡1(mod5)2^{2008} = \left(2^4\right)^{502} \equiv 1 \pmod{5}. So k≡4+6≡0(mod10)k \equiv 4 + 6 \equiv 0 \pmod{10}, and k2≡0(mod10)k^2 \equiv 0 \pmod{10}. Next, both 200822008^2 and 220082^{2008} are divisible by 44, so 4∣k4 \divides k. Hence 2k2^k is even and 2k=(24)k/4≡1(mod5)2^k = \left(2^4\right)^{k/4} \equiv 1 \pmod{5}, which gives 2k≡6(mod10)2^k \equiv 6 \pmod{10}. Therefore k2+2k≡0+6=6(mod10)k^2 + 2^k \equiv 0 + 6 = 6 \pmod{10}.

Problem 4

35. Since gcd⁡(6,49)=gcd⁡(8,49)=1\gcd(6, 49) = \gcd(8, 49) = 1 and φ(49)=49−7=42\varphi(49) = 49 - 7 = 42, Euler’s Theorem gives 642≡842≡1(mod49)6^{42} \equiv 8^{42} \equiv 1 \pmod{49}. Since 83=2×42−183 = 2 \times 42 - 1, we get 683×6=684≡16^{83} \times 6 = 6^{84} \equiv 1, i.e., 683≡6−1(mod49)6^{83} \equiv 6^{-1} \pmod{49}, and similarly 883≡8−1(mod49)8^{83} \equiv 8^{-1} \pmod{49}. Now 6×8=48≡−1(mod49)6 \times 8 = 48 \equiv -1 \pmod{49}, so 6−1≡−86^{-1} \equiv -8 and 8−1≡−6(mod49)8^{-1} \equiv -6 \pmod{49}. Therefore

683+883≡−8−6=−14≡35(mod49).6^{83} + 8^{83} \equiv -8 - 6 = -14 \equiv 35 \pmod{49}.