0% found this document useful (0 votes)
13 views52 pages

Modular Arithmetic

Uploaded by

aykkeork
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views52 pages

Modular Arithmetic

Uploaded by

aykkeork
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

CS 111 - Discrete Mathematics E

Fall 2024

Shoghakat Stepanyan October 31, 2024 1 / 24


Congruence Modulo 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).

Shoghakat Stepanyan October 31, 2024 2 / 24


Congruence Modulo 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).

Shoghakat Stepanyan October 31, 2024 2 / 24


Integers mod n

Definition
The set of integers mod n is the following set of integers:

Zn = {0, 1, 2, · · · , n − 1}.

Shoghakat Stepanyan October 31, 2024 3 / 24


Integers mod n

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}.

Shoghakat Stepanyan October 31, 2024 3 / 24


Modular Addition and Multiplication

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.

Shoghakat Stepanyan October 31, 2024 4 / 24


Modular Addition and Multiplication

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.

Shoghakat Stepanyan October 31, 2024 4 / 24


Algebraic properties
For all x, y , z ∈ Zn .
• x +n y ∈ Zn Closure under addition
1. x +n y = y +n x, Commutativity
2. (x +n y ) +n z = x +n (y +n z), Associativity
3. x +n 0 = x, Zero element
4. x +n (−x) = 0, Opposite element
• x ·n y ∈ Zn Closure under multiplication
5. x ·n y = y ·n x, Commutativity
6. (x ·n y ) ·n z = x ·n (y ·n z), Associativity
7. x ·n 1 = x, Identity element
8. x ·n x −1 = 1, Inverse element
9. x ·n (y +n z) = x ·n y +n x ·n z, Distributivity
10. x ·n 0 = 0.

Shoghakat Stepanyan October 31, 2024 5 / 24


Modular Subtraction
Proposition
Let n be a positive integer, and let a, b ∈ Zn . Then there is one
and only one x ∈ Zn such that a = b +n x.

Shoghakat Stepanyan October 31, 2024 6 / 24


Modular Subtraction
Proposition
Let n be a positive integer, and let a, b ∈ Zn . Then there is one
and only one x ∈ Zn 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.

Shoghakat Stepanyan October 31, 2024 6 / 24


Modular Subtraction
Proposition
Let n be a positive integer, and let a, b ∈ Zn . Then there is one
and only one x ∈ Zn 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.

Shoghakat Stepanyan October 31, 2024 6 / 24


Modular Subtraction
Proposition
Let n be a positive integer, and let a, b ∈ Zn . Then there is one
and only one x ∈ Zn 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.

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.

Shoghakat Stepanyan October 31, 2024 7 / 24


Modular Division

Remark 1
We cannot use the cancellation law in Zn . That is,

a ·n b = a ·n c ⇒
/ b = c.

E.g., in Z8 we have 2 · 6 = 2 · 2, but 6 6= 2.

Shoghakat Stepanyan October 31, 2024 7 / 24


Modular Division

Remark 1
We cannot use the cancellation law in Zn . That is,

a ·n b = a ·n c ⇒
/ b = c.

E.g., in Z8 we have 2 · 6 = 2 · 2, but 6 6= 2.

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.

Shoghakat Stepanyan October 31, 2024 7 / 24


Modular reciprocal

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.

Shoghakat Stepanyan October 31, 2024 8 / 24


Modular reciprocal

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.

Shoghakat Stepanyan October 31, 2024 8 / 24


Modular reciprocal

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 .

Shoghakat Stepanyan October 31, 2024 8 / 24


Modular reciprocal

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.

Shoghakat Stepanyan October 31, 2024 8 / 24


Modular reciprocal

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.

Shoghakat Stepanyan October 31, 2024 8 / 24


Modular reciprocal

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.

Shoghakat Stepanyan October 31, 2024 8 / 24


Modular inverse

Proposition
Let n be a positive integer and let a ∈ Zn . If a has a reciprocal in
Zn , then it has only one reciprocal.

Shoghakat Stepanyan October 31, 2024 9 / 24


Modular inverse

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 .

Shoghakat Stepanyan October 31, 2024 9 / 24


Modular inverse

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.

Shoghakat Stepanyan October 31, 2024 9 / 24


Modular inverse

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.

Shoghakat Stepanyan October 31, 2024 9 / 24


Modular Inverse

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.

Shoghakat Stepanyan October 31, 2024 10 / 24


Modular Division

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 .

Shoghakat Stepanyan October 31, 2024 11 / 24


Modular Division

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

5/8 7 = 5 ·8 7−1 = 5 ·8 7 = (5 · 7) mod 8 = 35 mod 8 = 3.

Shoghakat Stepanyan October 31, 2024 11 / 24


Invertible Elements of Zn

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.

Shoghakat Stepanyan October 31, 2024 12 / 24


Invertible Elements of Zn

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.

Shoghakat Stepanyan October 31, 2024 12 / 24


Finding Modular Inverses by Euclid’s extended algorithm

Example
Find 17−1 in Z117 .

Shoghakat Stepanyan October 31, 2024 13 / 24


Finding Modular Inverses by Euclid’s extended algorithm

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.

Hence, 17−1 = (−55) mod 117 = 62 in Z117 .

Shoghakat Stepanyan October 31, 2024 13 / 24


Solutions

1. Compute the following in Z10 :

52 − 7 · 4
.
3 · 24 + 9

Shoghakat Stepanyan October 31, 2024 14 / 24


Solutions

1. Compute the following in Z10 :

52 − 7 · 4
.
3 · 24 + 9

2. Solve the following equation in Z91 :

29x + 77 = 5.

Shoghakat Stepanyan October 31, 2024 14 / 24


Exercises
52 − 7 · 4 25 mod 10 − 28 mod 10 5−8 (−3) mod 10
1. = = = =
3 · 24 + 9 3 · (16 mod 10) + 9 3·6+9 18 mod 10 + 9
7 7 7 ∗
= = = = 7 · 7−1 = 1.
8+9 17 mod 10 7
* 7−1 is defined in Z10 as 7 is coprime to 10.

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 .

Shoghakat Stepanyan October 31, 2024 15 / 24


Solving Modular Equivalences

Example 1
Solve the equation

29x + 77 ≡ 5 (mod 91).

Shoghakat Stepanyan October 31, 2024 16 / 24


Solving Modular Equivalences

Example 1
Solve the equation

29x + 77 ≡ 5 (mod 91).

Solution: Since the solution of the equation 29x + 77 = 5 in Z91 is


x = 54 (see slide 15), then the solutions of the equation
29x + 77 ≡ 5 (mod 91) will be

x = 54 + 91k, where k ∈ Z.

Shoghakat Stepanyan October 31, 2024 16 / 24


Solving Modular Equivalences

Proposition
Let a, b, n ∈ Z with n > 0. Suppose a and n are relatively prime
and consider the equation

ax ≡ b (mod n).

Shoghakat Stepanyan October 31, 2024 17 / 24


Solving Modular Equivalences

Proposition
Let a, b, n ∈ Z with n > 0. Suppose a and n are relatively prime
and consider the equation

ax ≡ b (mod n).

The set of solutions to this equation is

{x0 + kn | k ∈ Z},

where x0 = a0−1 b0 in Zn , a0 = a mod n, b0 = b mod n. The integer


x0 is the only solution to this equation in Zn .

Shoghakat Stepanyan October 31, 2024 17 / 24


Solving Systems of Modular Equivalences
Example 2
Solve the system of equations

x ≡ 1 (mod 8)
2x ≡ 5 (mod 9)

Shoghakat Stepanyan October 31, 2024 18 / 24


Solving Systems of Modular Equivalences
Example 2
Solve the system of equations

x ≡ 1 (mod 8)
2x ≡ 5 (mod 9)

Solution: The solutions of the first equation x ≡ 1 (mod 8) are


x = 1 + 8k, where k ∈ Z. (1)
Now, we substitute 1 + 8k for x in the second equation, that is:
2 + 16k ≡ 5 (mod 9) ⇔
7k ≡ 3 (mod 9).
−1
From here, since 7 = 4 in Z9 (7 · 4 = 28 mod 9 = 1 in Z9 ), then
4 · 7k ≡ 4 · 3 (mod 9) ⇔ k ≡ 12 (mod 9) ⇔ k ≡ 3 (mod 9).
Hence, k = 3 + 9s, where s ∈ Z. From here and by equation (1),
x = 1 + 8(3 + 9s) = 25 + 72s, where s ∈ Z,
which is the set of all solutions of the system.
Shoghakat Stepanyan October 31, 2024 18 / 24
Chinese Remainder Theorem

Chinese Remainder Theorem


Let m1 , m2 , · · · , mn be pairwise relatively prime integers greater
than one, and let a1 , a2 , · · · , an ∈ Z. Then the system


 x ≡ a1 (mod m1 )
x ≡ a2 (mod m2 )


 ···
x ≡ an (mod mn )

has a unique solution mod m = m1 m2 · · · mn .

Shoghakat Stepanyan October 31, 2024 19 / 24


Chinese Remainder Theorem

Chinese Remainder Theorem


Let m1 , m2 , · · · , mn be pairwise relatively prime integers greater
than one, and let a1 , a2 , · · · , an ∈ Z. Then the system


 x ≡ a1 (mod m1 )
x ≡ a2 (mod m2 )


 ···
x ≡ an (mod mn )

has a unique solution mod m = m1 m2 · · · mn . That is, there is


unique solution x0 with 0 ≤ x0 < m, and all other solutions differ
from x0 by a multiple of m.

Shoghakat Stepanyan October 31, 2024 19 / 24


Solving Modular Equivalences
Example 3
Solve the system of equations

 x ≡ 1 (mod 8)
2x ≡ 5 (mod 9)
x ≡ 3 (mod 13)

Shoghakat Stepanyan October 31, 2024 20 / 24


Solving Modular Equivalences
Example 3
Solve the system of equations

 x ≡ 1 (mod 8)
2x ≡ 5 (mod 9)
x ≡ 3 (mod 13)

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

Fermat’s Little Theorem


If p is a prime and a is an integer not divisible by p, then

ap−1 ≡ 1 (mod p).

Shoghakat Stepanyan October 31, 2024 21 / 24


Fermat’s Little Theorem

Fermat’s Little Theorem


If p is a prime and a is an integer not divisible by p, then

ap−1 ≡ 1 (mod p).

Example 1
Let p = 3 and a = 20.

Shoghakat Stepanyan October 31, 2024 21 / 24


Fermat’s Little Theorem

Fermat’s Little Theorem


If p is a prime and a is an integer not divisible by p, then

ap−1 ≡ 1 (mod p).

Example 1
Let p = 3 and a = 20. Then

203−1 ≡ 1 (mod 3) ⇔ 202 ≡ 1 (mod 3) ⇔ 400 ≡ 1 (mod 3).

Shoghakat Stepanyan October 31, 2024 21 / 24


Fermat’s Little Theorem
Example 2
Find the remainder of 92378 when divided by 13.

Shoghakat Stepanyan October 31, 2024 22 / 24


Fermat’s Little Theorem
Example 2
Find the remainder of 92378 when divided by 13.

Solution: Since 9 and 13 are relatively prime, then

913−1 ≡ 1 (mod 13) ⇔ 912 ≡ 1 (mod 13).

Now, 2378 = 19 · 12 + 2 implies

92378 = 919·12+2 = (912 )19 · 92 .

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

Comets 2P/Encke, 4P/Faye, and 8P/Tuttle have orbital periods of


3 years, 8 years, and 13 years, respectively. The last perihelions of
each of these comets were in 2017, 2014 and 2008, respectively.

What is the next year in which all three of these comets will
achieve perihelion in the same year?

Shoghakat Stepanyan October 31, 2024 23 / 24


Home reading and Exercises

Reading: E.R. Scheinerman – Chapter 7, Sections 37, 38.


Exercises: 37.1-37.3, 37.10, 37.12, 37.13, (optional 37.4-27.9,
37.11, 37.14), 38.1-38.8, 39.16-39.19.

Reading: K. Rosen – 4.1 (Modular Arithmetic only),


4.4 (up to Pseudoprimes).
Exercises: – 4.1 – 13, 14, 20, 21, 24-37.
4.4 – 1-12, 19-22, 31-39.

Shoghakat Stepanyan October 31, 2024 24 / 24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy