Modular Arithmetic
Modular Arithmetic
Fall 2024
Proposition
Let n be a positive integer. If a ≡ b (mod n) and c ≡ d (mod n),
then a + c ≡ b + d (mod n) and ac ≡ bd (mod n).
Proposition
Let n be a positive integer. If a ≡ b (mod n) and c ≡ d (mod n),
then a + c ≡ b + d (mod n) and ac ≡ bd (mod n).
Example
Since 11 ≡ 5 (mod 6) and 8 ≡ 20 (mod 6), then
11 + 8 ≡ 5 + 20 (mod 6) ⇔ 19 ≡ 25 (mod 6)
and
11 · 8 ≡ 5 · 20 (mod 6) ⇔ 88 ≡ 100 (mod 6).
Definition
The set of integers mod n is the following set of integers:
Zn = {0, 1, 2, · · · , n − 1}.
Definition
The set of integers mod n is the following set of integers:
Zn = {0, 1, 2, · · · , n − 1}.
Example
Z8 = {0, 1, 2, 3, 4, 5, 6, 7}.
Definition
Let n be a positive integer, and let a, b ∈ Zn . Then the addition
mod n and the multiplication mod n are defined in the following
ways:
a +n b = (a + b) mod n,
a ·n b = (a · b) mod n.
Definition
Let n be a positive integer, and let a, b ∈ Zn . Then the addition
mod n and the multiplication mod n are defined in the following
ways:
a +n b = (a + b) mod n,
a ·n b = (a · b) mod n.
Example
Consider Z8 , and 5, 7 ∈ Z8 . Then
5 +8 7 = (5 + 7) mod 8 = 12 mod 8 = 4,
5 ·8 7 = (5 · 7) mod 8 = 35 mod 8 = 3.
Definition
Let n be a positive integer. Let a, b ∈ Zn . Then the subtraction
mod n is defined in the following way: a −n b is the unique x such
that a = b +n x.
Definition
Let n be a positive integer. Let a, b ∈ Zn . Then the subtraction
mod n is defined in the following way: a −n b is the unique x such
that a = b +n x.
Proposition
Let n be a positive integer and let a, b ∈ Zn . Then
a −n b = (a − b) mod n.
Definition
Let n be a positive integer. Let a, b ∈ Zn . Then the subtraction
mod n is defined in the following way: a −n b is the unique x such
that a = b +n x.
Proposition
Let n be a positive integer and let a, b ∈ Zn . Then
a −n b = (a − b) mod n.
Example
Consider Z8 , and 5, 7 ∈ Z8 . Then
5 −8 7 = (5 − 7) mod 8 = (−2) mod 8 = 6.
Shoghakat Stepanyan October 31, 2024 6 / 24
Modular Division
Remark 1
We cannot use the cancellation law in Zn . That is,
a ·n b = a ·n c ⇒
/ b = c.
Remark 1
We cannot use the cancellation law in Zn . That is,
a ·n b = a ·n c ⇒
/ b = c.
Remark 1
We cannot use the cancellation law in Zn . That is,
a ·n b = a ·n c ⇒
/ b = c.
Remark 2
We cannot define the division like we defined the subtraction, that
is, “a/n b is the unique x such that a = b ·n x”. Indeed:
• In Z8 we have 4 = 2 · 6 = 2 · 2, which means the above
mentioned x may not be unique.
• In Z8 there is no x with 5 = 2 · x (why?), which means the
above mentioned x may not even exist.
Definition
Let n be a positive integer and let a ∈ Zn . A reciprocal of a is an
element b ∈ Zn such that a ·n b = 1. An element of Zn that has a
reciprocal is called invertible.
Definition
Let n be a positive integer and let a ∈ Zn . A reciprocal of a is an
element b ∈ Zn such that a ·n b = 1. An element of Zn that has a
reciprocal is called invertible.
Example
0 has no reciprocal in any Zn , that is, 0 is not invertible.
Definition
Let n be a positive integer and let a ∈ Zn . A reciprocal of a is an
element b ∈ Zn such that a ·n b = 1. An element of Zn that has a
reciprocal is called invertible.
Example
0 has no reciprocal in any Zn , that is, 0 is not invertible.
4 has no reciprocal in Z6 .
Definition
Let n be a positive integer and let a ∈ Zn . A reciprocal of a is an
element b ∈ Zn such that a ·n b = 1. An element of Zn that has a
reciprocal is called invertible.
Example
0 has no reciprocal in any Zn , that is, 0 is not invertible.
4 has no reciprocal in Z6 .
The reciprocal of 3 in Z10 is 7.
Definition
Let n be a positive integer and let a ∈ Zn . A reciprocal of a is an
element b ∈ Zn such that a ·n b = 1. An element of Zn that has a
reciprocal is called invertible.
Example
0 has no reciprocal in any Zn , that is, 0 is not invertible.
4 has no reciprocal in Z6 .
The reciprocal of 3 in Z10 is 7. The reciprocal of 7 in Z10 is 3.
Definition
Let n be a positive integer and let a ∈ Zn . A reciprocal of a is an
element b ∈ Zn such that a ·n b = 1. An element of Zn that has a
reciprocal is called invertible.
Example
0 has no reciprocal in any Zn , that is, 0 is not invertible.
4 has no reciprocal in Z6 .
The reciprocal of 3 in Z10 is 7. The reciprocal of 7 in Z10 is 3.
The reciprocal of 1 in any Zn is 1.
Proposition
Let n be a positive integer and let a ∈ Zn . If a has a reciprocal in
Zn , then it has only one reciprocal.
Proposition
Let n be a positive integer and let a ∈ Zn . If a has a reciprocal in
Zn , then it has only one reciprocal.
Definition
Let n be a positive integer and let a ∈ Zn . If the reciprocal of a in
Zn exists, then it is called the inverse of a, and is denoted a−1 .
Proposition
Let n be a positive integer and let a ∈ Zn . If a has a reciprocal in
Zn , then it has only one reciprocal.
Definition
Let n be a positive integer and let a ∈ Zn . If the reciprocal of a in
Zn exists, then it is called the inverse of a, and is denoted a−1 .
Example
In Z10 we have 3−1 = 7.
Proposition
Let n be a positive integer and let a ∈ Zn . If a has a reciprocal in
Zn , then it has only one reciprocal.
Definition
Let n be a positive integer and let a ∈ Zn . If the reciprocal of a in
Zn exists, then it is called the inverse of a, and is denoted a−1 .
Example
In Z10 we have 3−1 = 7.
Remark
In Zn the notation 1
a for a−1 is wrong.
Proposition
Let n be a positive integer and let a ∈ Zn . If a is invertible and
b = a−1 , then b is invertible and a = b −1 . In other words,
(a−1 )−1 = a.
Definition
Let n be a positive integer and let b be an invertible element of
Zn . For an arbitrary element a ∈ Zn the division mod n is defined
in the following way: a/n b = a ·n b −1 .
Definition
Let n be a positive integer and let b be an invertible element of
Zn . For an arbitrary element a ∈ Zn the division mod n is defined
in the following way: a/n b = a ·n b −1 .
Example
Consider Z8 , and 5, 7 ∈ Z8 . Then
Theorem
Let n be a positive integer and let a ∈ Zn . Then a is invertible if
and only if a and n are relatively prime.
Theorem
Let n be a positive integer and let a ∈ Zn . Then a is invertible if
and only if a and n are relatively prime.
Corollary
Let n be a positive integer. Then any nonzero element a ∈ Zn is
invertible if and only if n is prime.
Example
Find 17−1 in Z117 .
Example
Find 17−1 in Z117 .
Solution:
117 = 6 · 17 + 15,
17 = 1 · 15 + 2,
15 = 7 · 2 + 1,
2 = 2 · 1 + 0.
1 = 15 − 7 · 2 =
= 15 − 7 · (17 − 1 · 15) = −7 · 17 + 8 · 15 =
= −7 · 17 + 8 · (117 − 6 · 17) = −55 · 17 + 8 · 117.
52 − 7 · 4
.
3 · 24 + 9
52 − 7 · 4
.
3 · 24 + 9
29x + 77 = 5.
2. 29x + 77 = 5 ⇔ 29x = 5 − 77
⇔ 29x = (−72) mod 91
⇔ 29x = 19
∗
⇔ x = 29−1 · 19 = 22 · 19 = 418 mod 91 = 54.
* 91 = 3 · 29 + 4,
29 = 7 · 4 + 1,
4 = 4 · 1.
1 = 29 − 7 · 4 = 29 − 7 · (91 − 3 · 29) = 22 · 29 − 7 · 91.
Hence, 29−1 = 22 mod 91 = 22 in Z91 .
Example 1
Solve the equation
Example 1
Solve the equation
x = 54 + 91k, where k ∈ Z.
Proposition
Let a, b, n ∈ Z with n > 0. Suppose a and n are relatively prime
and consider the equation
ax ≡ b (mod n).
Proposition
Let a, b, n ∈ Z with n > 0. Suppose a and n are relatively prime
and consider the equation
ax ≡ b (mod n).
{x0 + kn | k ∈ Z},
Solution: The solutions of the first two equations are (see slide 18)
x = 25 + 72s, where s ∈ Z. (2)
Now, we substitute 25 + 72s for x in the third equation, that is:
25 + 72s ≡ 3 (mod 13) ⇔
7s ≡ 4 (mod 13).
From here, since 7−1 = 2 in Z13 (7 · 2 = 14 mod 13 = 1 in Z13 ), then
s ≡ 2 · 4 (mod 13) ⇔ s ≡ 8 (mod 13).
Hence, s = 8 + 13t, where t ∈ Z. From here and by equation (2),
x = 25 + 72(8 + 13t) = 601 + 936t, where t ∈ Z.
Shoghakat Stepanyan October 31, 2024 20 / 24
Fermat’s Little Theorem
Example 1
Let p = 3 and a = 20.
Example 1
Let p = 3 and a = 20. Then
Hence,
92378 ≡ 92 (mod 13),
92378 ≡ 81 (mod 13),
92378 ≡ 3 (mod 13).
Therefor, the remainder of 92378 mod 13 = 3.
Shoghakat Stepanyan October 31, 2024 22 / 24
Exercise
What is the next year in which all three of these comets will
achieve perihelion in the same year?