7.2 Applications of Euler’s and Fermat’s Theorem.
i) Finding and using inverses.
From Fermat’s Little Theorem we see that if p is prime and p - a then
a
≡ 1 mod p, or equivalently ap−2 × a ≡ 1 mod p. This means that ap−2 is
the inverse of a modulo p or, in the language of congruence classes, [a]−1
p =
[ap−2 ]p in Z∗p .
An interesting question is with which method is it quickest to calculate
the modular inverse. Is it by Euclid’s Algorithm or by calculating ap−2 using,
for example, the method of successive squaring? In fact, both methods have
running time proportional to the number of decimal digits of a. For Euclid’s
algorithm this result on the running time is the content of Lame’s Theorem,
PJE p.226.
p−1
Aside III And in general, for (a, m) = 1 the inverse of a modulo m is
aφ(m)−1 . But now it isn’t reasonable to calculate aφ(m)−1 since it is difficult
to evaluate φ (m) for composite m. In fact we need to know that m is prime to
use φ (m) = m − 1, and it is another difficult task to verify whether a given
integer is prime or not. The largest known prime (as of September 2008)
is 243,112,609 − 1. (See http://en.wikipedia.org/wiki/Largest known prime for
further details).
A use of inverses is to solve linear congruences.
Example Find the integer solutions of 5x ≡ 6 mod 19.
Solution From Euler’s theorem 518 ≡ 1 mod 19 (because φ (19) = 18 since
19 is prime). So 5 × 517 ≡ 1 mod 19, i.e. 517 is the inverse of 5 mod 19. Thus
multiplying both sides of the equation by 517 gives
518 x ≡ 6 × 517 mod 19, i.e. x ≡ 6 × 517 mod 19.
Though this is an answer to the question we normally give x as the least
positive residue. Successive squaring gives
52 ≡ 6, 54 ≡ 17, 58 ≡ 4 and 516 ≡ 16 mod 19.
Thus x ≡ 6 × 5 × 16 ≡ 5 mod 19, which agrees with the answer found in
Chapter 3, but which should still be checked by substitution.
ii) Calculating powers.
With p = 13 and a = 4 we see that 412 ≡ 1 mod 13. Thus
8 2 2
4100 = 48×12+4 ≡ 412
4
≡ 112 (−3)2 ≡ 9 mod 13,
as we have seen before in Chapter 3, using the method of successive squaring.
1
iii) Solving non-linear congruences.
Example Solve x12 ≡ 3 mod 11.
Solution Any solution of this must satisfy gcd (x, 11) = 1 so Fermat’s Theorem gives x10 ≡ 1 mod 11. Thus our equation becomes x2 ≡ 3 mod 11. Now
check.
x x2 mod 11
1
1
2
4
3
9
4
5
5
3
Note that if x ≥ 6 then 11 − x ≤ 5 and x2 ≡ (11 − x)2 mod 11 so all
possible values of x2 mod 11 will be seen in the table.
From the table we see the answer is x ≡ 5 mod 11.
Example Show that x5 ≡ 3 mod 11 has no solutions.
Solution by contradiction. Assume x5 ≡ 3 mod 11 has solutions. Any
solution of this must satisfy gcd (x, 11) = 1 so Fermat’s Theorem gives
x10 ≡ 1 mod 11. Since 5|10 we square both sides of the congruence to get
1 ≡ x10 ≡ x5
2
≡ 32 ≡ 9 mod 11.
This is false and so the assumption is false and thus the congruence has no
solution.
Example Solve x7 ≡ 3 mod 11.
Solution Again x10 ≡ 1 mod 11 but this time 7 - 10, in fact gcd (7, 10) = 1.
From Euclid’s Algorithm we get
3 × 7 − 2 × 10 = 1.
Raise both sides of the congruence to the third power to get
3
2
33 ≡ x7 ≡ x3×7 ≡ x1+2×10 ≡ x x10 ≡ x mod 11.
Hence the solution is x ≡ 33 ≡ 5 mod 11.
Don’t forget to check your answer (by successive squaring of 5).
2
iv) Last decimal digits
Example Find the last two digits in the decimal expansion of 1399 .
Solution We have to calculate 1399 mod 100.
Euler’s Theorem tells us that 13φ(100) = 1340 ≡ 1 mod 10. Thus
2
1399 = 1340 1319 ≡ 12 1319 ≡ 1319 mod 100.
Now use successive squaring
132 ≡ 69, 134 ≡ 61, 138 ≡ 21, 1316 ≡ 41 mod 100.
(1)
Hence 1399 ≡ 41 × 69 × 13 ≡ 77 mod 100. So the last two digits of 1399 are
77, as already found in Chapter 3.
This method makes it easier to find the last two digits of 131010 , also asked
for in Chapter 3.
25
131010 = 1340 1310 ≡ 125 1310 ≡ 1310 mod 100.
Hence, using (1) , 131010 ≡ 69 × 21 ≡ 49 mod 100. Therefore, the last two
digits of 131010 are 49.
Question for students. What are the last three digits of 131010 ? See appendix.
iv) Is 235 + 1 divisible by 11? Here we look at 235 + 1 mod 11. Because 11 is
prime we could use Fermat’s Little Theorem to say 210 ≡ 1 mod 11. Thus
235 + 1 ≡ 25 + 1 ≡ 32 + 1 = 33 ≡ 0 mod 11,
i.e. 235 + 1 is divisible by 11.
Question for students. Show that 21194 + 1 is divisible by 65.
3
Appendix
Contents
1. Sieve of Eratosthenes
2. Prime Number Theorem
3. Lowest Common Multiples
4. Use of unique factorization
5. What are φ (100) and φ (1000) and their use
6. Further examples of Fermat’s Theorem
7. Wilson’s Theorem
8. Permutations on Z∗8
1) Sieve of Eratosthenes.
All the numbers from 2 up to 100
11
21
31
41
51
61
71
81
91
2
12
22
32
42
52
62
72
82
92
3
13
23
33
43
53
63
73
83
93
4
14
24
34
44
54
64
74
84
94
5
15
25
35
45
55
65
75
85
95
6
16
26
36
46
56
66
76
86
96
7
17
27
37
47
57
67
77
87
97
8
18
28
38
48
58
68
78
88
98
9
19
29
39
49
59
69
79
89
99
Delete multiples of 2 apart from 2 itself:
2
11
21
31
41
51
61
71
81
91
3
13
23
33
43
53
63
73
83
93
5
15
25
35
45
55
65
75
85
95
7
17
27
37
47
57
67
77
87
97
9
19
29
39
49
59
69
79
89
99
4
10
20
30
40
50
60
70
80
90
100
Delete multiples of 3 apart from 3 itself:
2
11
31
41
3
13
23
43
53
61
71
73
83
91
5
25
35
55
65
85
95
7
17
37
47
67
77
19
29
49
59
79
89
97
Delete multiples of 5 apart from 5 itself:
2
11
31
41
3
13
23
5
37
47
43
53
61
71
7
17
67
77
73
83
91
19
29
49
59
79
89
97
Delete multiples of 7 apart from 7 itself:
2
11
31
41
61
71
3
13
23
43
53
5
7
17
19
29
37
47
59
67
73
83
79
89
97
√
The next number is 11 which is greater than 100 and so there are no
multiples of it less than 100 that haven’t already been deleted in earlier
stages. Thus we are left with the 25 primes <100.
5
2) Prime Numbers.
For x > 0 let π (x) be the number of primes not exceeding x. So π (10) =
4, π (100) = 25, (as seen from the application of the Sieve of Eratosthenes in
the appendix), π (1000) = 168 and π (5000) = 669. Also
π 1023 = 1, 925, 320, 391, 606, 803, 968, 923,
due to Tomás Oliveira e Silva, 2007. Is there a simple formula for π (x)?
Theorem Prime Number Theorem (1896)
π (x)
→1
x/ ln x
as x → ∞.
This means that we can make |π (x) / (x/ ln x) − 1| as small as we like by
taking x sufficiently large. This difference is < 0.054 if x ≥ 109 , is < 0.039 if
x ≥ 1012 and is < 0.033 if x ≥ 1014 . So, for very large x the graph for π (x)
lies close to that of x/ ln x.
Proof not given.
You might in fact think that x/ ln x is not a good approximation to π (x).
If f (x) = x/ ln x then
f 1023 = 1, 888, 236, 877, 840, 225, 337, 613.6039952...
which seems quite a long way short of the true value of π (1023 ) above.
(See http://en.wikipedia.org/wiki/Prime-counting function for further details including a description of a better approximation to π (x).)
3) Lowest Common Multiples.
Let a, b be integers > 1, and let p1 , p2 , ..., pn be all the primes that divide
ab. Then
n
n
Q
Q
a=
pai i , b =
pbi i ,
i=1
i=1
for some ai , bi ≥ 0 for 1 ≤ i ≤ n.
Theorem
gcd (a, b) =
n
Q
pdi i with di = min (ai , bi ) for all 1 ≤ i ≤ n,
i=1
and
lcm (a, b) =
n
Q
pfi i with fi = max (ai , bi ) for all 1 ≤ i ≤ n.
i=1
6
And gcd (a, b) × lcm (a, b) = ab.
Proof The result for the gcd (a, b) was given in lectures.
For the lowest common multiple, recall the
Definition The lowest common multiple of integers a, b is the positive
integer f that satisfies
(1) a|f, b|f,
(2) if a|k, b|k then f |k.
Note that ab is a multiple of both a and b and thus a common multiple.
By part (2) of the definition lcm (a, b) |ab. In particular the primes dividing
lcm (a, b) come from the list p1 , p2 , ..., pn . Therefore
lcm (a, b) =
n
Q
pfi i
i=1
for some fi ≥ 0 for 1 ≤ i ≤ n.
The condition that a| lcm (a, b) implies ai ≤ fi while b| lcm (a, b) implies
bi ≤ fi for 1 ≤ i ≤ n. These combine to give max (ai , bi ) ≤ fi for 1 ≤ i ≤ n.
But lcm (a, b) is the least common multiple so we take fi = max (ai , bi ) for
1 ≤ i ≤ n.
Finally, since for all x, y we have
min (x, y) + max (x, y) = x + y,
(student to check this), then
n
Q
gcd (a, b) × lcm (a, b) =
min(ai ,bi )
pi
i=1
n
Q
=
n
Q
max(ai ,bi )
pi
i=1
min(ai ,bi )+max(ai ,bi )
pi
i=1
n
Q
=
i=1
pai +bi =
n
Q
i=1
pai
n
Q
pbi
i=1
= ab.
7
4) Example of use of unique factorization.
Example
For any m ≥ 2 there is no rational solution to q m = 2.
Solution by contradiction.
Assume that for some m ≥ 2 there exists a rational q : q m = 2.
Write q = a/b with a, b ∈ Z, so we get am = 2bm . First this means am > 1
and so a > 1 in which case it has a decomposition into primes. Thus
!m
n
n
Y
Y
pimai =
pai i
= 2bm .
i=1
i=1
By unique factorization, one of the primes in the product has to be 2, assume
p1 = 2 so a1 ≥ 1. Now either b = 1 or it is a product of primes, one of which
may be 2. So
n
n
Y
Y
mai
ma1
1+mb1
i
2
pi = 2
pmb
i
i=2
i=2
where b1 , and all other bi ≥ 0. By unique factorization the number of 2’s on
both sides are identical so ma1 = 1 + mb1 , i.e. m (a1 − b1 ) = 1 in which case
m divides 1. This contradicts m ≥ 2 and so the assumption is false and thus
for no m ≥ 2 can we find a rational solution of q m = 2.
√
One of the first proofs you examine at University is to prove that 2 is
irrational, i.e. no rational solutions of q 2 = 2. So here we have extended this
result.
5) What is φ (100)?
Lemma For all s ∈ Z,
gcd (r + s10, 100) = 1 ⇔ gcd (r, 10) = 1.
Proof (⇐) Assume gcd (r, 10) = 1. Assume for contradiction that ∃` 6= ±1
such that `|100 and `| (r + s10).
Then since 100 is not prime, `|100 implies there exists d 6= ±1 such that
d|` and d|10. But `| (r + s10) then implies that d| (r + s10).
Combining d|10 and d| (r + s10) gives d|r. We thus have d|10 and d|r
which with gcd (r, 10) = 1 means that d is either d = 1 or d = −1.
This contradicts d 6= ±1, so the assumption is false, thus the only common
divisors of r + s10 and 100 are ±1.
(⇒) The contrapositive of what we want to show, namely
gcd (r, 10) > 1 ⇒ gcd (r + s10, 100) > 1
8
is obvious.
Corollary
φ (100) = 40.
Proof Start from
φ (100) = |{1 ≤ n ≤ 100 : gcd (n, 100) = 1}|
= |{1 ≤ r ≤ 10, 0 ≤ s ≤ 9 : gcd (r + s10, 100) = 1}|
= |{1 ≤ r ≤ 10, 0 ≤ s ≤ 9 : gcd (r, 10) = 1}|
by the lemma
= 10 × |{1 ≤ r ≤ 10 : gcd (r, 10) = 1}|
= 10φ (10) = 40.
Example For m ≥ 1
φ (10m ) = 10φ 10m−1 .
Solution Simply write every 1 ≤ n ≤ 10m as r + s10n−1 with 1 ≤ r ≤ 10n−1
and 0 ≤ s ≤ 9. Then the same reasoning as before gives
gcd r + s10m−1 , 10m = 1 ⇔ gcd r, 10m−1 = 1,
for any s ∈ Z. And again, as before, this implies φ (10m ) = 10φ (10m−1 ) . Example Find the last three digits of 131010 .
Solution We need calculate 131010 mod 1000. From above φ (1000) = 10φ (100) =
400, and so 13400 ≡ 1 mod 1000. Thus
2
131010 ≡ 13400 13210 ≡ 13210 mod 1000.
Repeated squaring gives
132
134
138
1316
1332
1364
13128
=
≡
≡
≡
≡
≡
≡
169,
1692
5612
7212
8412
2812
9612
= 28561 ≡ 561 mod 1000,
= 314721 ≡ 721 mod 1000,
= 519841 ≡ 841 mod 1000,
= 707281 ≡ 281 mod 1000,
= 78961 ≡ 961 mod 1000,
= 923521 ≡ 521 mod 1000.
9
Combine
13210 =
≡
=
≡
=
≡
13128 × 1364 × 1316 × 132
521 × 961 × 841 × 169
500681 × 142129
681 × 129
87849
849 mod 1000.
Hence the last 3 digits of 131010 are 849.
6) Further examples of the use of Euler’s and Fermat’s Theorems.
Example Show that 21194 + 1 is divisible by 65.
Solution We need show that 65| (21194 + 1). Since 65 = 5 × 13 we need show
that 5| (21194 + 1) and 13| (21194 + 1).
First, since φ (5) = 4 we have 24 ≡ 1 mod 5. Hence
298 2
21194 + 1 = 24
2 + 1 ≡ 1298 × 4 + 1
= 5 ≡ 0 mod 5.
Secondly, since φ (13) = 12 we have 212 ≡ 1 mod 5. Hence
99
21194 + 1 = 212 26 + 1 ≡ 199 × 64 + 1
= 65 ≡ 0 mod 13.
Combining these we get the required result.
Example Is 221 prime?
Solution Fermat’s Little Theorem tells us that If 221 is prime then 2220 ≡
1 mod 221. Note that
220 = 128 + 64 + 16 + 8 + 4
= 2 7 + 26 + 2 4 + 23 + 22 .
10
Look at powers of 2 modulo 221.
2
n−1
n
mod 221
n 22 = 22
0
1
2
3
4
5
6
7
2
22 = 4
42 = 16
162 = 256 ≡ 35
352 = 1225 ≡ 120 ≡ −101
(−101)2 = 10201 ≡ 35
352 ≡ −101
(−101)2 ≡ 35.
So
2220 =
≡
≡
≡
7
6
4
3
2
22 22 22 22 22
35 × (−101) × (−101) × 35 × 16
220 × 220 × 16
16 mod 221.
Since 2220 6≡ 1 mod 221 we deduce that 221 is not prime.
Example You now notice that 221 is composite and in fact 221 = 17 ×
13. Use Fermat’s Little Theorem, and not the method of successive squaring
modulo 221, to check that 2220 ≡ 16 mod 221.
Solution. If x ≡ 2220 mod (17 × 13) then
x ≡ 2220 mod 17 and x ≡ 2220 mod 13.
By Fermat’s theorem we have 216 ≡ 1 mod 17 so
3
2220 = 213×16+12 ≡ 212 ≡ 24
≡ (−1)3 ≡ −1 ≡ 16 mod 17.
Similarly 212 ≡ 1 mod 13 so
2220 = 218×12+4 ≡ 24 = 16 ≡ 3 mod 13.
Thus our two equations become
x ≡ 16 mod 17 and x ≡ 3 mod 13
11
Such a system was solved in the Appendix to Chapter 3, using the Chinese
Remainder Theorem, where we found x ≡ 16 mod 221.
Example Solve x22 + x11 ≡ 2 mod 11.
Solution Any solution must have gcd (x, 11) = 1 and so, by By Fermat’s
Theorem,
x22 + x11 ≡ x2 + x ≡ x2 + 12x ≡ (x + 6)2 − 36 mod 11,
by completing the square. Thus we need only solve (x + 6)2 ≡ 2 + 36 ≡
5 mod 11. From the table
x x2 mod 11
1
1
2
4
3
9
4
5
5
3
we see that x + 6 ≡ 4 mod 11 and x + 6 ≡ −4 mod 11 are solutions, i.e. x ≡ 1
or 9 mod 11.
Example Show that there are no integer solutions (x, y) to
x12 − 11x6 y 5 + y 10 ≡ 8.
Solution We assume there are integer solutions. When we look at this
modulo 11 they remain solutions.
There are two cases.
First, it maybe that 11|y in which case the equation becomes x12 ≡
8 mod 11. For any solution of this we must have gcd (x, 11) = 1 so, again by
Fermat’s Theorem, x10 ≡ 1 mod 11 and so we get x2 ≡ 8 mod 11. From the
table above we see this has no solutions.
Secondly, perhaps 11 - y, i.e. gcd (y, 11) = 1. So Fermat’s Theorem again
gives both x10 , y 10 ≡ 1 mod 11. Thus
x12 − 11x6 y 5 + y 10 ≡ x12 + 1 ≡ x2 + 1 mod 11,
and so we are looking for solutions to x2 ≡ 7 mod 11. Again from the table
we see this has no solution.
In both cases our equation has no solutions modulo 11. This contradiction
means our original equation has no integer solutions.
12
7) Wilson’s Theorem.
Recall that
Z∗m = {[r]m : 1 ≤ r ≤ m, (r, m) = 1}
= {[r]m : 1 ≤ r ≤ m, ∃ [x]m ∈ Zm : [r]m [x]m = [1]m } .
Question What 1 ≤ r ≤ m are self-inverse modulo m, i.e. for which we can
we take [x]m = [r]m in [r]m [x]m = [1]m ? In other words, for which 1 ≤ r ≤ m
do we have r2 ≡ 1 mod m?
Answer given here only for m = p, prime.
Theorem x2 ≡ 1 mod p if, and only if, x ≡ 1 or −1 mod p.
Proof
x2 ≡ 1 mod p ⇔ p| x2 − 1
⇔ p| (x − 1) (x + 1)
⇔ p| (x − 1) or p| (x + 1)
since p prime
⇔ x ≡ 1 mod p or x ≡ −1 mod p.
Thus the only self-inverses in Z∗p are [1]p and [p − 1]p . As a corollary of
this we have
Theorem Wilson’s Theorem. If p is prime then
(p − 1)! ≡ −1 mod p.
Proof p.291. Take the product of all the classes in Z∗p :
Y
[r]p .
1≤r≤p−1
(r,p)=1
Rearrange, pairing up a class with its inverse, leaving [1]p and [p − 1]p
unpaired. So the product becomes
!
Y
−1
[1]p
[r]p [r]p
[p − 1]p = [p − 1]p .
pairs
Thus
Y
[r]p = [p − 1]p ,
1≤r≤p−1
(r,p)=1
13
which is equivalent to the stated result.
Example Calculate 20! mod 23.
Solution 23 is a prime so Wilson’s Theorem gives 22! ≡ −1 mod 23. But
22! = 22 × 21 × 20! ≡ (−1) × (−2) × 20!
≡ 2 × 20! mod 23.
By observation 12 is the inverse of 2 modulo 23 so
20! ≡ 12 × 2 × 20! ≡ 12 × 22! ≡ −12
≡ 11 mod 12.
8)
Permutations on
Z∗8
Example On Z∗8 = {1, 3, 5, 7}, (dropping the [...]8 ), we have four such permutations.
1 3 5 7
ρ1 =
= 1Z∗8 ,
1 3 5 7
1 3 5 7
ρ3 =
= (1, 3) ◦ (5, 7) ,
3 1 7 5
1 3 5 7
ρ5 =
= (1, 5) ◦ (3, 7) ,
5 7 1 3
1 3 5 7
ρ7 =
= (1, 7) ◦ (3, 5) .
7 5 3 1
Note that
ρb ◦ ρa ([r]8 ) = ρb (ρa ([r]8 )) = ρb ([ar]8 )
= [b (ar)]8 = [(ba) r]8
= ρba ([r]8 ) .
Hence ρb ◦ ρa = ρba . Thus we can draw up the multiplication table for these
permutations which can be compared with that for (Z∗8 , ×) :
◦
ρ1
ρ3
ρ5
ρ7
ρ1
ρ1
ρ3
ρ5
ρ7
ρ3
ρ3
ρ1
ρ7
ρ5
ρ5
ρ5
ρ7
ρ1
ρ3
×8
1
3
5
7
ρ7
ρ7
ρ5
ρ3
ρ1
1
1
3
5
7
3
3
1
7
5
5
5
7
1
3
7
7
5
3
1
The mapping Z∗8 → {ρ1 , ρ3 , ρ5 , ρ7 } , r 7→ ρr “preserves” the structure of
the table. Perhaps you can generalize this to a result for (Z∗m , ×)?
14
© Copyright 2026 Paperzz