MODULAR ARITHMETIC
STEVEN DALE CUTKOSKY
1. Relations, Rational Numbers and Modular Arithmetic
1.1. Relations. Suppose that X is a set. a relation on X is a subset
R ⊂ X × X = {(a, b) | a, b ∈ X}.
Write a ∼ b if (a, b) ∈ R. ∼ is an equivalence relation if
(1) a ∼ a for all a ∈ X. (∼ is reflexive)
(2) If a, b ∈ X and a ∼ b, then b ∼ a. (∼ is symmetric)
(3) If a, b, c ∈ X, a ∼ b and b ∼ c, then a ∼ c (∼ is transitive)
The significance of an equivalence relation is that it gives a partition of X.
Theorem 1.1. Suppose that X is a set, and ∼ is an equivalence relation on X. Let the
equivalence class of a ∈ X be
[a] = {b ∈ X | b ∼ a}.
Then
(1) a ∈ [a]
(2) if b ∈ [a] then [b] = [a].
Proof. Suppose that a ∈ X. Then a ∼ a, since ∼ is reflexive, so that a ∈ [a].
Suppose that b ∈ [a]. Then b ∼ a. Suppose that c ∈ [b]. Then c ∼ b. Thus c ∼ a and
c ∈ [a] since ∼ is transitive. It follows that [b] ⊂ [a]. Suppose that c ∈ [a]. Then c ∼ a.
Since ∼ is symmetric, a ∼ b. Since ∼ is transitive, c ∼ b and c ∈ [b]. It follows that
[a] ⊂ [b], so that [b] = [a].
Corollary 1.2. Suppose that X is a set, and ∼ is an equivalence relation on X. Then X
is the disjoint union of it’s equivalence classes; that is,
X = ∪a∈X [a]
and if a, b ∈ X are such that [a] ∩ [b] 6= ∅, then [a] = [b].
Proof. Since a ∈ [a] for all a ∈ X, X = ∪a∈X [a]. Suppose that a, b ∈ X and c ∈ [a] ∩ [b].
Then [c] = [a] and [c] = [b], so that [a] = [b].
If ∼ is an equivalence relation on X, then we define
X/ ∼= {[a] | a ∈ X}.
1
1.2. Congruence relations on the Integers. Suppose that n ≥ 2 is an integer. Define
a relation R ⊂ Z × Z by
R = {(a, b) ∈ Z × Z | m divides (b − a)}.
We write a ≡ b (mod) n if (a, b) ∈ R, and let [a]n be the equivalence class of a.
Theorem 1.3. ≡ (mod) n is an equivalence relation on Z.
By Corollary 1.2, the equivalence classes of ≡ (mod) n is a partition of Z (Z is the
disjoint union of its equivalence classes [a]n ).
If n = 2, the partition is into the even and odd integers,
E = {. . . , −4, −2, 0, 2, 4, . . .}
and
O = {. . . , −3, −1, 1, 3, . . .}.
If a ∈ Z is an even integer then its equivalence class [a]2 = E and if a ∈ Z is an odd
integer, then its equivalence class is [a]2 = O.
If n = 3, the partition is into three equivalence classes,
A = {. . . , −6, −3, 0, 3, 6, . . .},
B = {. . . , −5, −2, 1, 4, 6 . . .}
and
C = {. . . , −4, −1, 2, 5, . . .}.
If a ∈ Z, then [a]3 = A if a is a multiple of 3, [a]3 = B if a is one more than a multiple of
3, and [a]3 = C if a is 2 more than a multiple of 3.
In general,
Z/(≡ (mod) n) = {[0]n , [1]n , [2]n , . . . , [n − 1]n }
consists of n distinct equivalence classes. We write Zn = Z/(≡ (mod) n).
We now show that Zn has a natural addition and multiplication. We define
[a]n + [b]n = [a + b]n
for [a]n , [b]n ∈ Zn , and
[a]n [b]n = [ab]n
for [a]n , [b]n ∈ Zn .
We must verify that this is well defined. To establish this, we must show that we get
the same results under addition and multiplication, regardless of which representative of
an equivalence class we take. We settle this by proving the following Theorem.
Theorem 1.4. Suppose that a, b, c, d ∈ Z, a ≡ c (mod) n and b ≡ d (mod) n. Then
(1) [a + b]n = [c + d]n and
(2) [ab]n = [cd]n .
Proof. We prove 1 and leave the proof of 2 for the reader. By assumption, there exist
r, s ∈ Z such that a = c + rn and b = d + sn. Thus a + b = c + d + (r + s)n and
(a + b) ≡ (c + d) (mod) n. It follows that [a + b]n = [c + d]n .
2
Theorem 1.5. Consider Zn with the above addition and multiplication.
(1)
(2)
(3)
(4)
Addition satisfies the commutative and associative laws.
Multiplication satisfies the commutative and associative laws.
[0]n is an additive identity and [1]n is a multiplicative identity.
Every a ∈ Zn has an additive inverse −a ∈ Zn . If a = [x]n , then −a = [−x]n .
Theorem 1.6. Zn satisfies the cancellation law for multiplication if and only if n is a
prime number.
Proof. First assume that n is a prime number. We will show that the cancellation law for
multiplication holds. Suppose that a, b, c ∈ Zn , c 6= [0]n and ca = cb. We must show that
a = b. There exist x, y, z ∈ Z such that a = [x]n , b = [y]n and c = [z]n . Since ca = cb, we
have that [zx]n = [zy]n and thus zx ≡ zy (mod) n. We have that
z(x − y) = zx − zy = rn
for some r ∈ Z. Since n is a prime number, n divides z or n divides x − y, by Theorem
1.13 of the “Notes on Integers”. If n divides z, then z ≡ 0 (mod) n so that c = [z]n = [0]n ,
a contradiction. Thus we must have that n divides x − y, so that x ≡ y (mod) n, and
a = [x]n = [y]n = b.
Now suppose that n is not a prime number. Then there is a factorization n = rs where
r and s are positive integers with 1 < r < n and 1 < s < n. Since r and s are not
divisible by n, we have that [r]n 6= [0]n and [s]n 6= [0]n . Let a = [s]n , b = [0]n and c = [r]n .
ca = [rs]n = [0]n and cb = [r · 0]n = [0]n . Thus we have that ca = cb but a 6= b.
Since ≡ (mod) n preserves addition and multiplication, it is called a congruence relation.
1.3. Rational Numbers. Define a relation on Z×(Z\{0}) by (a, b) ∼ (c, d) if ad−bc = 0.
∼ is an equivalence relation. Denote the equivalence class of (a, b) by ab . We define the
rational numbers to be
Q = (Z × (Z \ {0})) / ∼ .
We can define addition on Q by
a c
ad + bc
+ =
b d
bd
and multiplication on Q by
ac
ac
= .
bd
bd
Both of these operations are well defined. The integers are naturally a subset of Q.
For an integer n, we usually write n for n1 ∈ Q. The additive identity of Q is 0, and
the multiplicitive identity of Q is 1. Every nonzero rational number ab ∈ Q has the
multiplicitive inverse ab ∈ Q.
3
1.4. Linear congruences. In this section we consider the explicit solution of congruences. Now that we know about rational numbers, we will find it convenient to regard the
integers as a subset of Q.
Suppose that a, b, c ∈ Z with b ≥ 2. Then x ∈ Z satisfies the congruence
ax ≡ c (mod) b
if and only if there is a y ∈ Z such that
ax + by = c.
Theorem 1.7. Suppose that a, b, c ∈ Z with b ≥ 2. Then the congruence
ax ≡ c (mod) b
has a solution x ∈ Z if and only if d = gcd(a, b) divides c. If the congruence has a solution
x ∈ Z, then there are exactly d different classes mod b of solutions.
Proof. The fact that the congruence has a solution x ∈ Z if and only if d divides c follows
from Theorem 1.7 of the “Notes on Integers”.
Now suppose that the congruence has a solution x0 ∈ Z. Then there exists y0 ∈ Z such
that x = x0 , y = y0 is a solution of
ax + by = c.
The integral solutions to ax + by = c are then x = x0 + x and y = y0 + y such that x, y
are integral solutions to
(1)
ax + by = 0.
Now ad , db ∈ Z and x = db t, y = − ad t for t ∈ Z are integral solutions to (1). We will show
that these are the only integral solutions to (1). Suppose x, y is an integral solution to
(1). Then ax = −by, so
b
a
x = − y.
d
d
Now gcd( ad , − db ) = 1 by Theorem 1.9 of the “Notes on Integers”. Thus ad |y and db |x, so
that
x
y
, a ∈ Z.
b
d
d
Set
x
t=
We have db t = x and
a
− t=
d
b
d
−a
d
b
d
∈ Z.
a
x = − x = y.
b
Thus the set of all integral solutions of ax + by = c is
b
a
x = x0 + t, y = y0 − t
d
d
4
with t ∈ Z. The d solutions
b
b
x0 , x0 + , . . . , x0 + (d − 1)
d
d
to the congruence are in distinct congruences classes mod b since their pairwise differences
b
b
b
(x0 + n ) − (x0 + m ) = (n − m)
d
d
d
are not divisible by b for 0 ≤ m < n ≤ d − 1.
Suppose that x = x0 + db t with t ∈ Z. Then t = qd + r with 0 ≤ r < d by Euclidean
division. Thus x ≡ x0 + r db (mod) b, and we see that there are exactly d different classes
mod b of solutions.
Example 1.8. Solve, if possible, the congruence
675x ≡ 18 (mod) 963.
To solve this, we first compute gcd(963, 657).
963
657
306
45
36
=
=
=
=
=
657 · 1 + 306
306 · 2 + 45
45 · 6 + 36
36 · 1 + 9
9 · 4.
Since d = gcd(963, 657) = 9 divides 18, the congruence can be solved, and the solutions
comprise 9 equivalence classes mod 963. From our calculation, we obtain that
9 = 22 · 657 + (−15) · 963.
Thus
657 · 44 ≡ 18 (mod) 963
and x0 = 44 is a solution. Since db = 963
9 = 107, the solutions of the congruence are the 9
equivalence classes
[44]963 , [44 + 107]963 , . . . , [44 + 856]963 .
It is also possible to solve simultaneous congruences. We state a theorem which is
applicable for solving pairs of congruences.
Theorem 1.9. Suppose that m, n, a, b ∈ Z and m, n ≥ 2. There exists x ∈ Z such that
x ≡ a (mod) m and x ≡ b (mod) n
if and only if
a ≡ b (mod) d
where d = gcd(m, n). If the pair of congruences has a solution x0 , then the solutions of
the pair of congruences are exactly the elements of the congruence class [x0 ]e , where e is
the least common multiple of m and n.
Example 1.10. Find an integer x such that
x ≡ 5 (mod) 12 and x ≡ 4 (mod) 17.
5
We see that such an x exists since gcd(12, 17) = 1, so
5 ≡ 4 (mod) gcd(12, 17).
So we must find integers r and s that satisfy the conditions
x = 5 + 12r = 4 + 17s
or solve the equation
12r − 17s = −1.
The Euclidean algorithm can be used, but trial and error yields
12 · 7 − 17 · 5 = −1,
or r = 7 and s = 5. Therefore
x = 5 + 84 = 4 + 85 = 89
is one solution of the pair of congruences. Since the least common multiple of 12 and 17
is 204, the congruence class [89]204 is the set of solutions to the pair of congruences.
Example 1.11. Solve the pair of congruences
5x ≡ 1 (mod) 12, 6x ≡ 7 (mod) 17.
First we find all of the solutions of
5x ≡ 1 (mod) 12.
Since the numbers are small, we proceed by trial and error and obtain 5 as a particular
solution. Then since gcd(5, 12) = 1, we know that the elements of the congruence class
[5]12 are the solutions of the congruence.
In the same manner we consider
6x ≡ 7 (mod) 17
and find that 4 is a solution. Since gcd(6, 17) = 1, we conclude that the elements of the
congruence class [4]17 are the solutions of this congruence.
Now suppose that x0 is a common solution of these two congruences; then x0 must lie in
the class [5]12 and also in the class [4]17 . In other words, x0 is a solution of the following
pair of congruences:
x0 ≡ 5 (mod) 12, x0 ≡ 4 (mod) 17.
From the Example 1.10, we know that the solutions of this pair are exactly the elements
of the congruence class [89]204 . Therefore x0 lies in the class [89]204 .
Conversely, suppose that y is in the congruence class [89]204 . Then
y = 89 + 204k
for some k ∈ Z, so that
y = 4 + 85 + 204k = 4 + (5 + 12k)17
and
6y = 24 + 6(5 + 12k)17 = 7 + (31 + 72k)17.
6
Moreover,
y = 5 + 84 + 204k = 5 + (7 + 17k)12
and
5y = 25 + 5(7 + 17k)12 = 1 + (37 + 85k)12.
Therefore we see that
5y ≡ 1 (mod) 12 and 6y ≡ 7 (mod) 17
and conclude that the solutions of the original pair of congruences are precisely the elements of [89]204 .
One of the most powerful theorems on simultaneous congruences is the Chinese Remainder Theorem.
Theorem 1.12. Suppose that the n integers mi with mi ≥ 2 for all i are pairwise relatively
prime; that is gcd(mi , mj ) = 1 if i 6= j. Suppose that a1 , . . . , an ∈ Z. Then the system of
n congruences
x ≡ a1 (mod) m1 , · · · , x ≡ an (mod) mn
has an integral solution x = x0 . Moreover, the solutions of the system of congruences are
exactly the elements of the congruence class [x0 ]m1 m2 ···mn .
Example 1.13. A band of 13 pirates confiscated a box of x gold coins. Uniform distribution of the coins resulted in a remainder of 8 coins. After two pirates were killed,
a redistribution left a remainder of 3 coins, and a redistribution after the death of three
more pirates resulted in a remainder of 5 coins. What is the minimal possible value of x?
We must solve the following system of congruences:
x ≡ 8 (mod) 13, x ≡ 3 (mod) 11, x ≡ 5 (mod) 8.
Since gcd(13, 11) = gcd(13, 8) = gcd(11, 8) = 1, we know by the Chinese Remainder
Theorem that the system has exactly one solution between 0 and 8 · 11 · 13. To find this
integer, we first solve the pair
x ≡ 8 (mod) 13, x ≡ 3 (mod) 11.
We seek integers r and s such that
x = 8 + 13r = 3 + 11s,
or
11s − 13r = 5.
Since
11 · 6 − 13 · 5 = 1,
we can take
s = 30 and r = 25.
Then
8 + 13 · 25 = 3 + 11 · 30 = 333
7
is one solution of the pair, and since 11·13 = 143, the solutions of the pair are the elements
of the congruence class [333]143 = [47]143 .
Now we consider the pair
x ≡ 47 (mod) 143 and x ≡ 5 (mod) 8.
To solve this pair we must find integers u and v such that
x = 47 + 143u = 5 + 8v
or
143u − 8v = −42.
Since
143 · 7 − 8 · 125 = 1
we see that we can use
u = 7 · (−42) and v = 125 · (−42).
Then
47 + 143 · 7 · (−42) = 5 + 8 · 125 · (−42) = −41995
is a solution of this pair. Since 8 · 11 · 13 = 1144, all the solutions of this pair, and
hence of the original system of three congruences, are the elements of the congruence class
[−41995]1144 . Since 333 is the smallest positive integer in that class, with
−41995 = −37 · 1144 + 333,
we conclude that 333 is the minimal value of x.
8
© Copyright 2026 Paperzz