Week 3
Week 3
MATH3301
UNSW, 2024
The typed lecture notes don’t contain extras such as exercises or sections with the *
symbol from the written lecture notes. However, these notes have all the necessary content
from the lectures with minor modifications.
Lecture 7
Algebraic Equations modulo m. We want to know how to solve congruences of the
form
ax ≡ b mod m.
Definition (Congruence class). The congruence class of a modulo m is the set of all
integers which are congruent to a modulo m.
Thus two integers a, b are in the same congruence class modulo m if a ≡ b mod m. In
symbols, the congruence class is the set
{b | a ≡ b mod m}
We think of ‘≡’ as partitioning the integers into congruence classes. For example, con-
sider the congruence classes modulo 4:
. . . -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 . . .
-4 0 4
-3 1 5
-6 -2 2 6
-5 -1 3
If n is a solution to the congruence
ax ≡ b mod m
then in fact any n′ in the same congruence class modulo m is also a solution:
n ≡ n′ mod m =⇒ an ≡ an′ ≡ b mod m.
This means that if we want to know all the solutions to ax ≡ b mod m, we just need to
determine which congruence classes give rise to solutions.
Example. To find all solutions to
2x ≡ 4 mod 6
we just need to check x ∈ {0, 1, 2, 3, 4, 5}, since every integer is congruent to one of these.
After doing this, we see that x = 2, 5 are valid solutions, and they are the only valid
solutions in the set {0, 1, 2, 3, 4, 5}. This means that any other number that is in the
congruence class of 2 or 5 is also a solution, i.e. 2, −4, 8, −10, . . . are solutions, as well as
5, −1, 11, −7, . . ., and these are the only solutions
Note that sometimes mod m equations have no solutions. For example, by checking
every x ∈ {0, 1, 2, 3, 4, 5}, we can see that 2x ≡ 5 mod 6 has no solutions!
1
NUMBER THEORY AND CRYPTOGRAPHY 2
Lecture 8
Last time we mostly proved the following result:
Theorem (Linear congruences in one variable). The equation
ax ≡ b mod m
has solutions if and only if
gcd(a, m)|b.
Furthermore, if gcd(a, m)|b, then there are exactly gcd(a, m) distinct congruence classes
(modulo m) which solve the equation.
Explicitly, if n satisfies ax ≡ b mod m and d = gcd(a, m), then
m m
n, n + , . . . , n + (d − 1)
d d
are also solutions, and
(i) these belong to distinct congruence classes modulo m
(ii) any solution to the equation is in fact congruent to one of these integers.
Today we will complete the proof of the proposition by proving (ii).
Remark. Any integer of the form n + k md is congruent to one of
m m
n, n + , . . . , n + (d − 1)
d d
This means that it is enough to show that if n′ is any solution to ax ≡ b mod m, then it
can be written as
m
n′ = n + k
d
Before we begin the proof, we need a few facts:
Proposition (Modular cancellation). Let d be a nonzero integer. Then
a ≡ b mod m ⇐⇒ da ≡ db mod dm
Proof. We have the following equivalences:
a ≡ b mod m ⇐⇒ a − b = km for some integer k
⇐⇒ da − db = kdm for some integer k
⇐⇒ da ≡ db mod dm
□
Lemma. If a, b are two integers, then a/ gcd(a, b) and b/ gcd(a, b) are relatively prime.
This should be intuitively clear because gcd(a, b) is the product of the common prime
factors of a and b. Dividing by gcd(a, b) gets rid of these factors.
Proof. To prove this, we use the fact that two integers are relatively prime if and only if
there is an integer linear combination of them which sums to one. To begin, we use the
extended Euclidean algorithm to find n, m such that
an + bm = gcd(a, b).
Dividing both sides by gcd(a, b), we get
a b
n+ m = 1.
gcd(a, b) gcd(a, b)
NUMBER THEORY AND CRYPTOGRAPHY 5
a b
This gives an integer linear combination of gcd(a,b) and gcd(a,b) which sums to one, so they
are relatively prime.
We could also prove this lemma by using the fact that two integers are relatively prime
if and only if they have no common prime factors. We demonstrate this with an example,
say 30 and 80. Observe that
30 = 2 × 3 × 5
80 = 2 × 2 × 2 × 2 × 5
so gcd(30, 80) = 2 × 5 = 10. Now dividing both by gcd(30, 80) gets rid of all the common
factors, so we must be left with integers that are relatively prime, in this case 3 and 8. □
Lemma. If a|bc and gcd(a, b) = 1, then a|c.
Proof. We use the Fundamental Theorem to write the unique prime factorisations:
a = a1 . . . ak
b = b1 . . . bl
c = c1 . . . cm
where the ai , bi , ci are all prime. Since a|bc, this means that each ai is a bi or a ci . Since
gcd(a, b) = 1, this means that no ai is a bi . But then every ai must be a ci , so a|c. □
Proof of proposition concluded. Given that n, n′ are solutions to
ax ≡ b mod m
we aim to show that
m
n′ − n = k
d
for some integer k, where d = gcd(a, m).
Since n, n′ are both solutions,
an ≡ an′ mod m.
Therefore, since d divides a and m, we have by the proposition on modular cancellation:
a a m
n ≡ n′ mod ,
d d d
′
which means that d | d (n − n). Our first lemma above says that ad and m
m a
d are relatively
prime, so our second lemma implies that m |(n ′ − n). This exactly means we can write
d
m
n − n = k′ ,
′
d
′
for some integer k as required. □
In high school, when faced with the equation
2x = 5
we solve by dividing both sides by 2, or equivalently multiplying both sides by 1/2:
2x = 5 =⇒ x = 5/2.
But in modular arithmetic, we don’t always have numbers like 1/2, so we can’t always do
this. For example, we saw that
2x ≡ 5 mod 6
has no solutions.
Definition (Modulo m inverse). We say a is a modulo m inverse for a if
aa ≡ 1 mod m
NUMBER THEORY AND CRYPTOGRAPHY 6
Lecture 9
If a modulo m inverse of a exists, then we may cancel the a’s on both sides of an
equation.
Corollary. Suppose gcd(a, m) = 1. Then
ab ≡ ac mod m ⇐⇒ b ≡ c mod m.
Proof. Note that
b ≡ c mod m =⇒ ab ≡ ac mod m
always holds. For the other direction, note that gcd(a, m) = 1 implies there exists a
modulo m inverse a. Therefore
ab ≡ ac mod m =⇒ aab ≡ aac mod m
=⇒ b ≡ c mod m,
since aa ≡ 1 mod m. □
Example. Solve 3x ≡ 9 mod 11.
Note that gcd(3, 11) = 1. We may rewrite this as
3x ≡ 3 × 3 mod 11.
By the corollary, we can just cancel the 3’s from both sides of the equation:
x≡3 mod 11.
Warning: If we try this when gcd(a, m) > 1, then we won’t get all of the solutions! For
example
3x ≡ 9 mod 12
yields a solution
x ≡ 3 mod 12
by cancelling the 3, but we miss the other solutions of
x ≡ 7, 11 mod 12.
In these cases, we still need to use our proposition from last time.
Solving systems of equations. The next natural question is: how do we find solutions
to a system of equations?
a1 x ≡ b1 mod m1
a2 x ≡ b2 mod m2
..
.
ar x ≡ br mod mr
We will answer this question for a special case:
Theorem (Chinese Remainder Theorem). Let m1 , . . . , mr be pairwise relatively prime
integers. Then the system
x ≡ a1 mod m1
x ≡ a2 mod m2
..
.
x ≡ ar mod mr
is solved by a unique congruence class modulo M := m1 m2 . . . mr .
NUMBER THEORY AND CRYPTOGRAPHY 8
Example. An ancient Chinese general wants to know how many troops he has after a
battle. He lines them up in rows of 9 and finds he has 1 soldier left over. He lines them up
in rows of 10 and finds he has 5 soldiers left over. Finally, he lines them up in rows of 11
and again he has 1 soldier left over. By direct observation, he knows that he has between
1000 and 2000 troops. How many troops does he have exactly?
To phrase the problem in terms of modular arithmetic, let n be the number of troops.
Our information tells us that n is a solution to the following system of congruences:
x≡1 mod 9
x≡5 mod 10
x≡1 mod 11.
Our theorem says that n is uniquely determined up to multiples of 9 × 10 × 11 = 990, and
the proof of the theorem will give us a method for finding n explicitly.
The proof of the Chinese remainder theorem will require the following simple lemma.
Lemma. Suppose a1 , . . . , ak are pairwise relatively prime, and suppose ai |b for each i =
1, . . . , k. Then (a1 . . . ak )|b.
Proof. We will leave the proof of this lemma as an exercise, but let’s give an example
to see that the statement is false without the assumption of relative primality. Consider
10 and 15, which are not relatively prime. We have 10 | 30 and 15 | 30, but clearly their
product 150 does not divide 30. □
Proof of theorem. We first construct a solution to the system
x ≡ a1 mod m1
x ≡ a2 mod m2
..
.
x ≡ ar mod mr .
Set M := m1 m2 . . . mr , and define
M M M
M1 := , M2 := , . . . , Mr := .
m1 m2 mr
Q
Note that Mi and mi are relatively prime, because Mi = j̸=i mj , and our hypotheses
imply that mj is relatively prime to mi for all j ̸= i. This means that a modulo mi inverse
exists for Mi , i.e. there exist integers M1 , M2 , . . . , Mr such that
M 1 M1 ≡ 1 mod m1
M 2 M2 ≡ 1 mod m2
..
.
Mr Mr ≡ 1 mod mr .
Now consider the integer
n = a 1 M1 M1 + a 2 M 2 M2 + . . . + a r M r M r .
I claim that n is a solution to the system of equations. To check this, reduce n modulo
mi for each i. Since Mj is a multiple of mi for each j ̸= i, reducing modulo mi kills every
term except the ith one. Thus, we have
n ≡ ai Mi Mi ≡ ai mod mi ,
NUMBER THEORY AND CRYPTOGRAPHY 9
Any integer of the form n = 595 + 990k satisfies the system. The number of troops the
general had left is the integer of this form that lies between 1000 and 2000, namely
595 + 990 = 1585.