Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
In this section we continue the discussion of congruences from Chapter 7 to develop some nice number
theoretic results that have applications to prime number testing and cryptography.
Recall that two integers a and b are said to be relatively prime if gcd(a, b) = 1.
φ(m) = the number of integers in {1, 2, . . . , m} that are relatively prime with m.
This function is due to mathematician Leonhard Euler, who introduced it in 17631 – although it was
Gauss in 1801 who first used φ for the name of this function.2
Example 1. We have φ(1) = 1 since 1 is the only integer in {1} relatively prime with 1.
Example 2. To compute φ(8), we count how many integers in {1, 2, . . . , 8} are relatively prime with 8.
These are 1, 3, 5, and 7; so φ(8) = 4. Values of φ(m) for small values of m are given below.
integers 1 ≤ k ≤ m
m φ(m)
such that gcd(k, m) = 1
1 1 1 integers 1 ≤ k ≤ m
m φ(m)
2 1 1 such that gcd(k, m) = 1
3 1, 2 2 11
4 1, 3 2 12
5 1, 2, 3, 4 4 13
6 1, 5 2 14
7 1, 2, 3, 4, 5, 6 6 15
8 1, 3, 5, 7 4 16
9 1, 2, 4, 5, 7, 8 6
10 1, 3, 7, 9 4
Exercise 3. Complete the above table for φ(m) for m = 11, 12, . . . , 16.
If p is prime, then all integers from 1 to p − 1 are relatively prime with p. This implies the following
result:
Lemma 4. If p is prime, then φ(p) = p − 1.
Exercise 5. Is the converse of the above statement true? That is, if m > 2 is an integer such that
φ(m) = m − 1, does it necessarily follow that m is prime?
Exercise 6. If p is prime and k ∈ N, what is φ(pk )?
Exercise 7. If p and q are prime, prove that φ(pq) = (p − 1)(q − 1).
The main result we would like to prove in this section is called Euler’s Theorem, which implies another
result called Fermat’s Little Theorem as a special case.
Euler’s Theorem
Suppose x, m ∈ N and gcd(x, m) = 1. Then
Proof: This is the special case of Euler’s theorem where m is prime, and using Lemma 4.
Although FLT is a special case of Euler’s Theorem, it was FLT that was actually proven first – in 1736,
also by Euler.3 Only in 1763 did Euler publish the generalization that is Euler’s Theorem.4
Before we prove Euler’s Theorem, let’s look at some examples.
Lemma 12 (The Cancellation Law). Let a, m ∈ N with gcd(a, m) = 1. If ax ≡ ay (mod m), then
x ≡ y (mod m).
Proof. Since ax ≡ ay (mod m), we have m | (ax − ay), or m | a(x − y). Since gcd(a, m) = 1, we can
apply Lemma 10, which proves that m | (x − y), or that x ≡ y (mod m).
http://eulerarchive.maa.org//pages/E054.html
4 Euler, Theoremata arithmetica nova methodo demonstrata, http://eulerarchive.maa.org//pages/E271.html
MAT102H5Y Summer 2019
φ(m) φ(m)
Y Y
xai ≡ ai (mod m) ⇒ xφ(m) ≡ 1 (mod m).
i=1 i=1
This is nice, because instead of trying to find factors of large numbers, we could just determine the
congruence class of am−1 modulo m, and if it isn’t [1], then m can’t be prime.
MAT102H5Y Summer 2019
What does this mean?? First, note that when you are asked to solve the system of congruences, this
means to find x (modulo M ) that satisfies all the congruences simultaneously.
Example 13. Consider the system of congruences
x ≡ 3 (mod 5)
x ≡ 1 (mod 7)
5 https://en.wikipedia.org/wiki/Chinese_remainder_theorem
MAT102H5Y Summer 2019
How can we construct solutions to these systems of congruences efficiently? To do this, we first define
the notion of the multiplicative inverse of an integer modulo m.
Multiplicative Inverse
Given a, m ∈ N and gcd(a, m) = 1, we say that b is a multiplicative inverse of a modulo m if
ab ≡ 1 (mod m).
Exercise 15. Let m = 15 and a = 2. Verify that b = 8 and b = 53 are both inverses of 2 modulo 15.
Usually, when working modulo m, we are interested in finding the specific inverse in the range 1 ≤ b < m,
to keep numbers small. We will call this quantity the multiplicative inverse of a modulo m.
Example 16. The multiplicative inverse of 7 modulo 30 is 13, since (7)(13) = 91 ≡ 1 (mod 30).
Exercise 17. Prove that x ≡ atm2 + bsm1 (mod m1 m2 ) satisfies both congruences in the given system.
Exercise 18. Prove that x ≡ atm2 + bsm1 (mod m1 m2 ) is the only solution to the given system modulo
m1 m2 .
Example 19. Once again consider the system
x ≡ 3 (mod 5)
x ≡ 1 (mod 7)
• Let M = m1 m2 · · · mn .
• For each i = 1, 2, . . . , n:
Example 20. Applying the above algorithm to Sunzi’s system, we have M = 3 · 5 · 7 = 105, and the
quantities
a1 = 2 m1 = 3 b1 = 35 t1 = 2
a2 = 3 m2 = 5 b2 = 21 t2 = 1
a3 = 2 m3 = 7 b3 = 15 t3 = 1
3
X
Hence we calculate ai bi ti = 2 · 35 · 2 + 3 · 21 · 1 + 2 · 15 · 1 = 140 + 63 + 30 = 233, and so the solution is
i=1
a mod m = the remainder obtained from the Division Algorithm when a is divided by m.
Bob computes N = pq, (p − 1)(q − 1), and d, the multiplicative inverse of e modulo (p − 1)(q − 1).
Then, Bob publishes the public key (e, N ) and keeps the other quantities private.
Suppose Alice wants to send the message x to Bob. They can ensure privacy of the data transmitted in
this manner:
Thus we have
y d ≡ x · (xM )k (mod N ) ≡ x · (1)k (mod N ) ≡ x (mod N ).
This means Bob successfully recovers Alice’s original message x.
Example 21. Suppose Bob picks p = 7, q = 13 as two primes, so that N = 91 and M = (6)(12) = 72.
Also, Bob picks e = 5, which has multiplicative inverse d = 29 modulo M . (Check this!)
Bob’s public key is (N = 91, e = 5).
Alice wants to transmit the message ROFL. To do this she first represents it numerically:
R O F L → 18 15 6 12
Then she computes xe mod N for each number x in the message, and sends the results to Bob.
Additional Exercises
In the following exercises, define the operation a mod m to be the remainder obtained from the Division
Algorithm when a is divided by m.
3. Solve for x in the following congruences of the form ax + b ≡ c (mod m). That is, determine the
congruence class of x among [0], [1], . . . , [m − 1].
(Hint: You may use the results of the previous exercise.)
Wilson’s Theorem states that if p is prime, then (p − 1)! ≡ −1 (mod p), where (p − 1)! is the
factorial of p − 1, defined by (p − 1)! = (p − 1)(p − 2) · · · (2)(1).
8. Verify that Wilson’s Theorem holds for p = 5 and p = 7.
9. For larger primes, instead of naively multiplying out (p − 1)!, we make use of the fact that we are
working modulo p. For example, suppose we want to verify the theorem for p = 19.
(a) Except for [1] and [18], list all congruence classes modulo 19.
(b) For each congruence class listed in (a), try to pair it up with its inverse. E.g. the inverse of [2] is
[10], since 2 · 10 ≡ 1 (mod 19). Are you able to completely pair all of them up?
(c) How would you use (b) to prove 18! ≡ −1 (mod 19)?
10. (Difficult) Prove Wilson’s Theorem by repeating the process in the previous exercise, but for a general
prime p. A crucial step in the proof is to show that one can always partition the set of congruence
classes {[2], [3], . . . , [p − 2]} into pairs {[a], [b]} such that ab ≡ 1 (mod p). Why does each [a] have an
inverse modulo p?