Week 2
Week 2
MATH3301
BRYCE KERR, 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 4
Last week, we found a necessary and sufficient condition for solving linear Diophantine
equations, spread out over several results. We will restate and reprove it (all in one place
this time).
Theorem (Solution to linear Diophantine equation in 2 variables). Let a, b, c be fixed
integers. The equation
ax + by = c
has integer solutions if and only if gcd(a, b)|c.
Proof. First, suppose ax + by = c has a solution. Then there exist integers n, m such that
an + bm = c. Since gcd(a, b)|a and gcd(a, b)|b, the properties of divisibility imply
gcd(a, b)|(an + bm).
Thus, gcd(a, b)|c as desired.
For the converse, suppose that gcd(a, b)|c. Then there exists some integer d such that
c = d gcd(a, b). The extended Euclidean algorithm finds integers n and m such that
gcd(a, b) = an + bm.
But then
c = d gcd(a, b) = d(an + bm) = a(dn) + b(dm),
so x = dn, y = dm is a solution to the equation ax + by = c.
□
We are now equipped to prove the Fundamental Theorem of Arithmetic, but we need
some preliminary definitions and results first.
Definition (Relatively prime). We say a, b are relatively prime (or coprime) if gcd(a, b) =
1. Equivalently (due to the extended Euclidean algorithm), there exist n, m such that
an + bm = 1.
For example, 6 and 25 are relatively prime (despite not being prime themselves). The
following lemma clarifies the relationship between primarily and relative primality; it says
that a prime number is relatively prime with anything, except multiples of itself.
Lemma. Suppose p is prime and a is any integer which is not a multiple of p. Then p
and a are relatively prime.
Proof. Note that gcd(a, p)|p. But since p is prime, gcd(a, p) = 1 or gcd(a, p) = p. In the
former case, a and p are relatively prime. In the latter case, p = gcd(a, p)|a. □
The lemma allows us to prove the following proposition, which is the crucial ingredient
in the Fundamental Theorem:
1
NUMBER THEORY AND CRYPTOGRAPHY 2
Lecture 5
Si numerus a numerorum b, c differentiam metitur, b et c secundum a congui
dicuntur, sin minus, incongrui : ipsum a modulum appellamus.1
With this opening sentence, Gauss introduced the world to modular arithmetic in his
magnum opus, the Disquisitiones Arithmeticae. It was completed in 1798, when he was
21, although it was not published until 1801.
Modular arithmetic will play a central role in our class as well. Here are two examples
of patterns that baffled mathematicians in the centuries preceding Gauss.
p (p − 1)! + 1
2 (2 − 1)! + 1 = 2
3 (3 − 1)! + 1 = 3
5 (5 − 1)! + 1 = 25 = 5 × 5
11 3628801 = 329891 × 11
13 479001601 = 36846277 × 13
.. ..
. .
Note that p is not a factor of (p − 1)! or 1, but when we add it, it becomes a factor of
the sum. What makes this pattern difficult to grapple with is that prime factors behave
unpredictably with respect to addition.
a a7 − a
1 0
2 7
2 − 2 = 126 = 7 × 18
3 37 − 3 = 2184 = 7 × 312
4 47 − 4 = 16380 = 7 × 2340
.. ..
. .
Through modular arithmetic, we will be able to prove these results, and gain some
insight as to why they work. In order to introduce the key idea of modular arithmetic, let
us first consider a much more naı̈ve problem:
Problem. Find the last digit of 971216 + 523121 .
Evidently, we do not want to multiply out this number in full detail. What makes this
problem trivial is the following simple observation (think for yourselves why it is true!):
Observation.
(a) The last digit of ab only depends on the last digit of a and the last digit of b.
(b) The last digit of a + b only depends on the last digit of a and the last digit of b.
By observation (b), it’s enough to find the last digit of 971216 and 523121 individually,
and then sum them.
1If a number a divides the difference of the numbers b and c, b and c are said to be congruent relative
to a; if not, b and c are noncongruent. The number a is called the modulus.
NUMBER THEORY AND CRYPTOGRAPHY 5
Last digit of 971216 : Using observation (a) (216 times), we deduce that the last digit of
971216 must be the same as the last digit of 1216 , i.e. 1.
Last digit of 523121 : Similarly, the last digit of 523121 must be the same as the last digit
of 3121 . Now powers of 3 are not as nice as powers of 1. To get around this, we write out
a few powers of 3, until we see that 34 = 81. To exploit this fact, we write
Modular arithmetic is really just a way of generalising observation (a) and (b) to arbi-
trary bases (not just base 10), and exploiting these observations for maximum leverage.
Definition (Congruence modulo m). Let a, b, m be integers. We say a is congruent to b
modulo m if m|(a − b). Equivalently, a and b have the same remainder after division by
m. We write this as a ≡ b mod m.
Here are some examples:
a ≡ b mod 10 ⇐⇒ a and b have the same last digit.
a ≡ b mod 2 ⇐⇒ a and b are both even or both odd.
a ≡ b mod 12 ⇐⇒ A clock looks the same after a hours or b hours.
Make sure you understand these examples!
Here is the key proposition that makes modular arithmetic work. Note that when
m = 10, this simply reduces to our statement about last digits.
Proposition (Addition/multiplication commutes with reduction modulo m). Suppose
a ≡ a′ and b ≡ b′ mod m. Then:
(1) a + b ≡ a′ + b′ mod m
(2) ab ≡ a′ b′ mod m
In this context, the word “commutes” means that it doesn’t matter which order you do
things. In other words, we can add a and b first then reduce modulo m or we can reduce
modular m first (to get a′ and b′ ) and then add. Either way, we get the same answer.
Proof. By our assumptions, m|(a − a′ ) and m|(b − b′ ). First, we show m|((a + b) − (a′ + b′ )):
a + b − (a′ + b′ ) = (a − a′ ) + (b − b′ )
which is divisible by m by the properties of divisibility. Next, we show m|(ab − a′ b′ ):
ab − a′ b′ = ab − a′ b + a′ b − a′ b′
= (a − a′ )b + a′ (b − b′ )
which is divisible by m by properties of divisibility. □
NUMBER THEORY AND CRYPTOGRAPHY 6
Lecture 6
In the last lecture we defined a ≡ b mod m to mean any of the following (they are all
equivalent):
(i) m|(a − b)
(ii) a and b have the same remainder upon division by a
(iii) a = b + km where k is some (possibly negative) integer
We then proved the following proposition.
Proposition (Addition/multiplication commutes with reduction modulo m). Suppose
a ≡ a′ and b ≡ b′ mod m. Then:
(1) a + b ≡ a′ + b′ mod m
(2) ab ≡ a′ b′ mod m
Remark. It follows easily (by induction) that if ai ≡ a′i mod m for i = 1, . . . , n, then
a1 + . . . + an ≡ a′1 + . . . + a′n mod m
and
a1 . . . an ≡ a′1 . . . a′n mod m
Today, we will take a careful look at how this proposition gets used by sketching some
applications of modular arithmetic. Soon, however, you will start using it on autopilot
without thinking too much. First though, one more piece of terminology. Observe that
any integer a is congruent modulo m to exactly one of 0, 1, . . . , m − 1. Indeed, the division
algorithm tells us that
a = qm + r for some integer 0 ≤ r < m,
so a − r = qm is divisible by m. Because of this, we will use the phrase ‘reduce a modulo
m’ to mean ‘find which of 0, 1, . . . , m − 1 that a is congruent to’.
Notation. Sometimes people use the notation “a mod m” for the reduction of a modulo
m. So then we have an equivalence
a ≡ b mod m ⇐⇒ a mod m = b mod m.
Warning: On the left side the “ mod m” indicates that the ≡ symbol is to be understood
as a congruence modulo m, whereas on the right side, the = is an ordinary equality between
two integers in the range 0, . . . , m − 1.
With this terminology, let us re-examine our problem from last time:
Problem. Find the last digit of 971216 + 523121 :
Expressed with our new terminology, the problem is asking us to reduce 971216 + 523121
modulo 10. Since addition commutes with reduction modulo m, it is enough to reduce
971216 and 523121 separately and then add. Let’s start with 971216 .
We can think of 971216 as a product of 216 numbers (all of which happen to be the
same), so in order to reduce 971216 modulo 10, we can first reduce 971 modulo 10 and
then multiply. Since
971 ≡ 1 mod 10
then
971216 ≡ 1216 ≡ 1 mod 10
A similar argument shows that since
523 ≡ 3 mod 10
NUMBER THEORY AND CRYPTOGRAPHY 7
we have
523121 ≡ 3121 mod 10
While this is an improvement, we must further simplify 3121 modulo 10. To do this, we
break up this product into simpler numbers. Ideally, we want something like 1 raised to
some power, since this is easily computed,. This leads us to the observation from last time
that 34 = 81 and 3121 = (34 )30 × 3 = 8130 × 3. We now use our proposition and the fact
that
81 ≡ 1 mod 10
to deduce that
523121 ≡ 3121 ≡ (34 )30 × 3 ≡ 8130 × 3 ≡ 1 × 3 ≡ 3 mod 10.
Therefore,
971216 + 523121 ≡ 1 + 3 ≡ 4 mod 10.
From now on, when you do this kind of problem, I don’t expect you to justify every
step in such pedantic detail. You can just write:
971216 + 523121 ≡ 1216 + 3121 mod 10
4 30
≡ 1 + (3 ) ·3 mod 10
≡ 1 + 8130 · 3 mod 10
30
≡ 1 + 1 · 3 mod 10
≡ 4 mod 10
Let us try a similar problem:
Problem. Reduce 175 · 4737 modulo 12.
There are many ways of proceeding; we could start by observing that
175 ≡ 55 ≡ 7 mod 12.
We also have
47 ≡ 11 ≡ −1 mod 12.
Putting this together, we get
175 · 4737 ≡ 7 · (−1)37 ≡ −7 mod 12.
To get this into the range {0, 1, . . . , 11} we just add 12:
175 · 4737 ≡ 7 · (−1)37 ≡ −7 ≡ 5 mod 12.
Divisibility tests. Now let’s use modular arithmetic to prove some well-known divisibility
tests. Let a be an integer, written in base 10, with digits an , . . . , a1 , a0 . By ‘written in
base 10’ we mean that
Xn
n n−1
a = an (10 ) + an−1 (10 ) + . . . + a1 (10) + a0 = ai (10i )
i=0