0% found this document useful (0 votes)
19 views169 pages

Uu 24 25 Discretemathematics 05

The document is a lecture on Discrete Mathematics, specifically focusing on Number Theory, Divisibility, and Modular Arithmetic. It covers definitions, examples, theorems, and properties related to divisibility, congruences, and the Division Algorithm. The content is structured for a Spring 2024-2025 course at Üsküdar University, taught by Dr. Fatih Temiz.

Uploaded by

rodiyahwuraola53
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)
19 views169 pages

Uu 24 25 Discretemathematics 05

The document is a lecture on Discrete Mathematics, specifically focusing on Number Theory, Divisibility, and Modular Arithmetic. It covers definitions, examples, theorems, and properties related to divisibility, congruences, and the Division Algorithm. The content is structured for a Spring 2024-2025 course at Üsküdar University, taught by Dr. Fatih Temiz.

Uploaded by

rodiyahwuraola53
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/ 169

COME104

Discrete Mathematics
Fatih Temiz, PhD
fatih.temiz@uskudar.edu.tr

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 1 / 53


Number Theory

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 2 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
If a and b are integers with a ̸= 0, we say that a divides b if there is an
integer c such that
b
b = ac (or equivalently, if is an integer).
a
When a divides b, we say that a is a factor or divisor of b, and that b is a
multiple of a. The notation a | b denotes that a divides b. We write a ∤ b
when a does not divide b.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 3 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
If a and b are integers with a ̸= 0, we say that a divides b if there is an
integer c such that
b
b = ac (or equivalently, if is an integer).
a
When a divides b, we say that a is a factor or divisor of b, and that b is a
multiple of a. The notation a | b denotes that a divides b. We write a ∤ b
when a does not divide b.

Example
7
3̸ | 7, because 3 is not an integer. However, 3 | 12 because 12 = 3 · 4.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 3 / 53


Number Theory Divisibility and Modular Arithmetic

Example
Let n and d be positive integers. How many positive integers not
exceeding n are divisible by d?

The positive integers divisible by d are all the integers of the form dk,
where k is a positive integer.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 4 / 53


Number Theory Divisibility and Modular Arithmetic

Example
Let n and d be positive integers. How many positive integers not
exceeding n are divisible by d?

The positive integers divisible by d are all the integers of the form dk,
where k is a positive integer.
Hence, the number of positive integers divisible by d that do not
exceed n equals the number of integers k with 0 < dk ≤ n, or with
0 < k ≤ dn .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 4 / 53


Number Theory Divisibility and Modular Arithmetic

Example
Let n and d be positive integers. How many positive integers not
exceeding n are divisible by d?

The positive integers divisible by d are all the integers of the form dk,
where k is a positive integer.
Hence, the number of positive integers divisible by d that do not
exceed n equals the number of integers k with 0 < dk ≤ n, or with
0 < k ≤ dn .
Therefore, there are dn positive integers not exceeding n that are
 

divisible by d.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 4 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let a, b, and c be integers, where a ̸= 0. Then
(i) If a | b and a | c, then a | (b + c).
(ii) If a | b, then a | bc for all integers c.
(iii) If a | b and b | c, then a | c.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 5 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let a, b, and c be integers, where a ̸= 0. Then
(i) If a | b and a | c, then a | (b + c).
(ii) If a | b, then a | bc for all integers c.
(iii) If a | b and b | c, then a | c.

Corollary
If a, b, c ∈ Z, where a ̸= 0, such that a | b and a | c, then
a | (mb + nc) whenever m, n ∈ Z.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 5 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem (The Division Algorithm)


Let a be an integer and d a positive integer. Then there exist unique
integers q and r , with 0 ≤ r < d, such that

a = dq + r .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 6 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem (The Division Algorithm)


Let a be an integer and d a positive integer. Then there exist unique
integers q and r , with 0 ≤ r < d, such that

a = dq + r .

Definition
In the equality given in the Division Algorithm, d is called the divisor, a is
called the dividend, q is called the quotient, and r is called the remainder.
This notation is used to express the quotient and remainder:

r = a mod d.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 6 / 53


Number Theory Divisibility and Modular Arithmetic

What are the quotient and remainder when 101 is divided by 11?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 7 / 53


Number Theory Divisibility and Modular Arithmetic

What are the quotient and remainder when 101 is divided by 11?

101 = 11 · 9 + 2

Hence, the quotient when 101 is divided by 11 is 9 = 101 ÷ 11, and


the remainder is 2 = 101 mod 11.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 7 / 53


Number Theory Divisibility and Modular Arithmetic

What are the quotient and remainder when 101 is divided by 11?

101 = 11 · 9 + 2

Hence, the quotient when 101 is divided by 11 is 9 = 101 ÷ 11, and


the remainder is 2 = 101 mod 11.
What are the quotient and remainder when -11 is divided by 3?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 7 / 53


Number Theory Divisibility and Modular Arithmetic

What are the quotient and remainder when 101 is divided by 11?

101 = 11 · 9 + 2

Hence, the quotient when 101 is divided by 11 is 9 = 101 ÷ 11, and


the remainder is 2 = 101 mod 11.
What are the quotient and remainder when -11 is divided by 3?

−11 = 3 · (−4) + 1.

Hence, the quotient when −11 is divided by 3 is −4 = −11 ÷ 3, and


the remainder is 1 = −11 mod 3.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 7 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
If a and b are integers and m is a positive integer, then a is congruent to b
modulo m if m divides a − b. We use the notation a ≡ b (mod m) to
indicate that a is congruent to b modulo m. We say that a ≡ b (mod m)
is a congruence and that m is its modulus (plural moduli).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 8 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
If a and b are integers and m is a positive integer, then a is congruent to b
modulo m if m divides a − b. We use the notation a ≡ b (mod m) to
indicate that a is congruent to b modulo m. We say that a ≡ b (mod m)
is a congruence and that m is its modulus (plural moduli).

Although both notations a ≡ b (mod m) and a mod m = b include


“mod,” they represent fundamentally different concepts. The first
represents a relation on the set of integers, whereas the second
represents a function.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 8 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let a and b be integers, and let m be a positive integer. Then a ≡ b
(mod m) if and only if a mod m = b mod m.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 9 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let a and b be integers, and let m be a positive integer. Then a ≡ b
(mod m) if and only if a mod m = b mod m.

Determine whether 17 is congruent to 5 modulo 6 and whether 24


and 14 are congruent modulo 6.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 9 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let a and b be integers, and let m be a positive integer. Then a ≡ b
(mod m) if and only if a mod m = b mod m.

Determine whether 17 is congruent to 5 modulo 6 and whether 24


and 14 are congruent modulo 6.
Because 6 divides 17 − 5 = 12, we see that 17 ≡ 5 (mod 6).
However, because 24 − 14 = 10 is not divisible by 6, we see that
24 ̸≡ 14 (mod 6).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 9 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let m be a positive integer. The integers a and b are congruent modulo m
if and only if there is an integer k such that a = b + km.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 10 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let m be a positive integer. The integers a and b are congruent modulo m
if and only if there is an integer k such that a = b + km.

Theorem
Let m be a positive integer. If a ≡ b (mod m) and c ≡ d (mod m), then

a + c ≡ b + d (mod m) and ac ≡ bd (mod m).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 10 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let m be a positive integer. The integers a and b are congruent modulo m
if and only if there is an integer k such that a = b + km.

Theorem
Let m be a positive integer. If a ≡ b (mod m) and c ≡ d (mod m), then

a + c ≡ b + d (mod m) and ac ≡ bd (mod m).

Because 7 ≡ 2 (mod 5) and 11 ≡ 1 (mod 5),

18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5)

and that
77 = 7 · 11 ≡ 2 · 1 = 2 (mod 5).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 10 / 53


Number Theory Divisibility and Modular Arithmetic

We must be careful working with congruences. Some properties we


may expect to be true are not valid.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 11 / 53


Number Theory Divisibility and Modular Arithmetic

We must be careful working with congruences. Some properties we


may expect to be true are not valid.
If ac ≡ bc (mod m), the congruence a ≡ b (mod m) may be false.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 11 / 53


Number Theory Divisibility and Modular Arithmetic

We must be careful working with congruences. Some properties we


may expect to be true are not valid.
If ac ≡ bc (mod m), the congruence a ≡ b (mod m) may be false.
Similarly, if a ≡ b (mod m) and c ≡ d (mod m), the congruence
ac ≡ b d (mod m) may be false.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 11 / 53


Number Theory Divisibility and Modular Arithmetic

We must be careful working with congruences. Some properties we


may expect to be true are not valid.
If ac ≡ bc (mod m), the congruence a ≡ b (mod m) may be false.
Similarly, if a ≡ b (mod m) and c ≡ d (mod m), the congruence
ac ≡ b d (mod m) may be false.

Corollary
Let m be a positive integer and let a and b be integers. Then

(a + b) mod m = ((a mod m) + (b mod m)) mod m

and
ab mod m = ((a mod m)(b mod m)) mod m.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 11 / 53


Number Theory Divisibility and Modular Arithmetic

Find the value of (193 mod 31)4 mod 23.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 12 / 53


Number Theory Divisibility and Modular Arithmetic

Find the value of (193 mod 31)4 mod 23.


193 mod 31 = 6859 mod 31 = 8.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 12 / 53


Number Theory Divisibility and Modular Arithmetic

Find the value of (193 mod 31)4 mod 23.


193 mod 31 = 6859 mod 31 = 8.
(193 mod 31)4 mod 23 = 84 mod 23

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 12 / 53


Number Theory Divisibility and Modular Arithmetic

Find the value of (193 mod 31)4 mod 23.


193 mod 31 = 6859 mod 31 = 8.
(193 mod 31)4 mod 23 = 84 mod 23
84 mod 23 = 4096 mod 23 = 2.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 12 / 53


Number Theory Divisibility and Modular Arithmetic

Arithmetic Moduo m

We can define arithmetic operations on Zm , the set of nonnegative


integers less than m, that is, the set {0, 1, . . . , m − 1}.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 13 / 53


Number Theory Divisibility and Modular Arithmetic

Arithmetic Moduo m

We can define arithmetic operations on Zm , the set of nonnegative


integers less than m, that is, the set {0, 1, . . . , m − 1}.
In particular, we define addition of these integers, denoted by +m , by

a +m b = (a + b) mod m,

and we define multiplication of these integers, denoted by ·m , by

a ·m b = (a · b) mod m.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 13 / 53


Number Theory Divisibility and Modular Arithmetic

Find 7 +11 9 and 7 ·11 9 in Zm .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 14 / 53


Number Theory Divisibility and Modular Arithmetic

Find 7 +11 9 and 7 ·11 9 in Zm .

7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5,

and
7 ·11 9 = (7 · 9) mod 11 = 63 mod 11 = 8.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 14 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.


5 The additive inverse of any a ∈ Zm is m − a, i.e.,

a + (m − a) = (m − a) + a = 0.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.


5 The additive inverse of any a ∈ Zm is m − a, i.e.,

a + (m − a) = (m − a) + a = 0.

6 Multiplication is closed, i.e., for any a, b ∈ Zm , ab ∈ Zm .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.


5 The additive inverse of any a ∈ Zm is m − a, i.e.,

a + (m − a) = (m − a) + a = 0.

6 Multiplication is closed, i.e., for any a, b ∈ Zm , ab ∈ Zm .


7 Multiplication is commutative, i.e., for any a, b ∈ Zm , ab = ba.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.


5 The additive inverse of any a ∈ Zm is m − a, i.e.,

a + (m − a) = (m − a) + a = 0.

6 Multiplication is closed, i.e., for any a, b ∈ Zm , ab ∈ Zm .


7 Multiplication is commutative, i.e., for any a, b ∈ Zm , ab = ba.
8 Multiplication is associative, i.e., for any a, b, c ∈ Zm , (ab)c = a(bc).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.


5 The additive inverse of any a ∈ Zm is m − a, i.e.,

a + (m − a) = (m − a) + a = 0.

6 Multiplication is closed, i.e., for any a, b ∈ Zm , ab ∈ Zm .


7 Multiplication is commutative, i.e., for any a, b ∈ Zm , ab = ba.
8 Multiplication is associative, i.e., for any a, b, c ∈ Zm , (ab)c = a(bc).
9 1 is a multiplicative identity, i.e., for any a ∈ Zm , a × 1 = 1 × a = a.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Operations in Zm
1 Addition is closed, i.e., for any a, b ∈ Zm , a + b ∈ Zm .
2 Addition is commutative, i.e., for any a, b ∈ Zm , a + b = b + a.
3 Addition is associative, i.e., for any a, b, c ∈ Zm ,

(a + b) + c = a + (b + c).

4 0 is an additive identity, i.e., for any a ∈ Zm , a + 0 = 0 + a = a.


5 The additive inverse of any a ∈ Zm is m − a, i.e.,

a + (m − a) = (m − a) + a = 0.

6 Multiplication is closed, i.e., for any a, b ∈ Zm , ab ∈ Zm .


7 Multiplication is commutative, i.e., for any a, b ∈ Zm , ab = ba.
8 Multiplication is associative, i.e., for any a, b, c ∈ Zm , (ab)c = a(bc).
9 1 is a multiplicative identity, i.e., for any a ∈ Zm , a × 1 = 1 × a = a.
10 The distributive property is satisfied, i.e., for any a, b, c ∈ Zm ,

a(b + c) = (ab) + (ac) and (a + b)c = (ac) + (bc).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 15 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The naive way to compute g A is by repeated multiplication by g .

g 2 =g · g (mod N)
g 3 =g · g 2 (mod N)
4 3
g =g · g (mod N)
..
.
g A =g · g A−1 (mod N)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 16 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The naive way to compute g A is by repeated multiplication by g .

g 2 =g · g (mod N)
g 3 =g · g 2 (mod N)
4 3
g =g · g (mod N)
..
.
g A =g · g A−1 (mod N)
First observe that we can avoid using large amount of memory

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 16 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The naive way to compute g A is by repeated multiplication by g .

g 2 =g · g (mod N)
g 3 =g · g 2 (mod N)
4 3
g =g · g (mod N)
..
.
g A =g · g A−1 (mod N)
First observe that we can avoid using large amount of memory
However if A is large, this algorithm is completely impractical. For
example, if A ≈ 21000 , then the naive algorithm would take longer
than the estimated age of the universe!

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 16 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The idea is to use the binary expansion of the exponent A to convert


the calculation of g A into a succession of squaring and multiplications.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 17 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The idea is to use the binary expansion of the exponent A to convert


the calculation of g A into a succession of squaring and multiplications.
An example will make the idea clear.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 17 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The idea is to use the binary expansion of the exponent A to convert


the calculation of g A into a succession of squaring and multiplications.
An example will make the idea clear.
Suppose that we want to compute 3218 (mod 1000).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 17 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The idea is to use the binary expansion of the exponent A to convert


the calculation of g A into a succession of squaring and multiplications.
An example will make the idea clear.
Suppose that we want to compute 3218 (mod 1000).
The first step is to write 218 as a sum of powers of 2,

218 = 2 + 23 + 24 + 26 + 27

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 17 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Modular Exponentiation

The idea is to use the binary expansion of the exponent A to convert


the calculation of g A into a succession of squaring and multiplications.
An example will make the idea clear.
Suppose that we want to compute 3218 (mod 1000).
The first step is to write 218 as a sum of powers of 2,

218 = 2 + 23 + 24 + 26 + 27

Then 3218 becomes


3 +24 +26 +27 3 4 6 7
3218 = 32+2 = 32 · 32 · 32 · 32 · 32

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 17 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Powering Algorithm

Notice that it is relatively easy to compute the sequence of values


2 3 4
3, 32 , 32 , 32 , 32 , . . . ,

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 18 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Powering Algorithm

Notice that it is relatively easy to compute the sequence of values


2 3 4
3, 32 , 32 , 32 , 32 , . . . ,

Further, since we only need these values modulo 1000, we never need
to store more than three digits.
i 0 1 2 3 4 5 6 7
i
32 (mod 1000) 3 9 81 561 721 841 281 961

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 18 / 53


Number Theory Divisibility and Modular Arithmetic

Fast Powering Algorithm

Notice that it is relatively easy to compute the sequence of values


2 3 4
3, 32 , 32 , 32 , 32 , . . . ,

Further, since we only need these values modulo 1000, we never need
to store more than three digits.
i 0 1 2 3 4 5 6 7
i
32 (mod 1000) 3 9 81 561 721 841 281 961
3 +24 +26 +27 3 4 6 7
3218 = 32+2 = 32 · 32 · 32 · 32 · 32
≡ 9 · 561 · 721 · 281 · 961 (mod 1000)
≡ 489 (mod 1000)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 18 / 53


Number Theory Divisibility and Modular Arithmetic

Primes and Greatest Common Divisors

Definition
An integer p greater than 1 is called prime if the only positive factors of p
are 1 and p. A positive integer that is greater than 1 and is not prime is
called composite.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 19 / 53


Number Theory Divisibility and Modular Arithmetic

Primes and Greatest Common Divisors

Definition
An integer p greater than 1 is called prime if the only positive factors of p
are 1 and p. A positive integer that is greater than 1 and is not prime is
called composite.

Theorem (The Fundamental Theorem of Arithmetic)


Every integer greater than 1 can be written uniquely as a prime or as the
product of two or more primes, where the prime factors are written in
order of nondecreasing size.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 19 / 53


Number Theory Divisibility and Modular Arithmetic

Primes and Greatest Common Divisors

Definition
An integer p greater than 1 is called prime if the only positive factors of p
are 1 and p. A positive integer that is greater than 1 and is not prime is
called composite.

Theorem (The Fundamental Theorem of Arithmetic)


Every integer greater than 1 can be written uniquely as a prime or as the
product of two or more primes, where the prime factors are written in
order of nondecreasing size.

Example
100 = 22 52 , 641 = 641, 999 = 33 · 37, 1024 = 210

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 19 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem

If n is a composite integer, then n has a prime divisor less than or equal to n.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 20 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem

If n is a composite integer, then n has a prime divisor less than or equal to n.

Theorem
There are infinitely many primes.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 20 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem

If n is a composite integer, then n has a prime divisor less than or equal to n.

Theorem
There are infinitely many primes.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 20 / 53


Number Theory Divisibility and Modular Arithmetic

Greatest Common Divisors and Least Common Multiples

Definition
Let a and b be integers, not both zero. The largest integer d such that
d | a and d | b is called the greatest common divisor of a and b. The
greatest common divisor of a and b is denoted by gcd(a, b).

What is the greatest common divisor of 24 and 36?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 21 / 53


Number Theory Divisibility and Modular Arithmetic

Greatest Common Divisors and Least Common Multiples

Definition
Let a and b be integers, not both zero. The largest integer d such that
d | a and d | b is called the greatest common divisor of a and b. The
greatest common divisor of a and b is denoted by gcd(a, b).

What is the greatest common divisor of 24 and 36?


The positive divisors of 24 are 1, 2, 3, 4,6, 8, 12, and 24.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 21 / 53


Number Theory Divisibility and Modular Arithmetic

Greatest Common Divisors and Least Common Multiples

Definition
Let a and b be integers, not both zero. The largest integer d such that
d | a and d | b is called the greatest common divisor of a and b. The
greatest common divisor of a and b is denoted by gcd(a, b).

What is the greatest common divisor of 24 and 36?


The positive divisors of 24 are 1, 2, 3, 4,6, 8, 12, and 24.
The positive divisors of 36 are 1, 2, 3, 4,6, 9, 12, 18 and 36.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 21 / 53


Number Theory Divisibility and Modular Arithmetic

Greatest Common Divisors and Least Common Multiples

Definition
Let a and b be integers, not both zero. The largest integer d such that
d | a and d | b is called the greatest common divisor of a and b. The
greatest common divisor of a and b is denoted by gcd(a, b).

What is the greatest common divisor of 24 and 36?


The positive divisors of 24 are 1, 2, 3, 4,6, 8, 12, and 24.
The positive divisors of 36 are 1, 2, 3, 4,6, 9, 12, 18 and 36.
The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 21 / 53


Number Theory Divisibility and Modular Arithmetic

Greatest Common Divisors and Least Common Multiples

Definition
Let a and b be integers, not both zero. The largest integer d such that
d | a and d | b is called the greatest common divisor of a and b. The
greatest common divisor of a and b is denoted by gcd(a, b).

What is the greatest common divisor of 24 and 36?


The positive divisors of 24 are 1, 2, 3, 4,6, 8, 12, and 24.
The positive divisors of 36 are 1, 2, 3, 4,6, 9, 12, 18 and 36.
The positive common divisors of 24 and 36 are 1, 2, 3, 4, 6, and 12.
Hence, gcd(24, 36) = 12.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 21 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The integers a and b are relatively prime if gcd(a, b) = 1.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 22 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The integers a and b are relatively prime if gcd(a, b) = 1.

Definition
The integers a1 , a2 , . . . , an are pairwise relatively prime if gcd(ai , aj ) = 1
whenever 1 ≤ i < j ≤ n.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 22 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The integers a and b are relatively prime if gcd(a, b) = 1.

Definition
The integers a1 , a2 , . . . , an are pairwise relatively prime if gcd(ai , aj ) = 1
whenever 1 ≤ i < j ≤ n.

What is the greatest common divisor of 17 and 22?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 22 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The integers a and b are relatively prime if gcd(a, b) = 1.

Definition
The integers a1 , a2 , . . . , an are pairwise relatively prime if gcd(ai , aj ) = 1
whenever 1 ≤ i < j ≤ n.

What is the greatest common divisor of 17 and 22?


The integers 17 and 22 have no positive common divisors other than
1, so that gcd(17, 22) = 1.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 22 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The integers a and b are relatively prime if gcd(a, b) = 1.

Definition
The integers a1 , a2 , . . . , an are pairwise relatively prime if gcd(ai , aj ) = 1
whenever 1 ≤ i < j ≤ n.

What is the greatest common divisor of 17 and 22?


The integers 17 and 22 have no positive common divisors other than
1, so that gcd(17, 22) = 1.
The integers 17 and 22 are relatively prime, because gcd(17, 22) = 1.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 22 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The integers a and b are relatively prime if gcd(a, b) = 1.

Definition
The integers a1 , a2 , . . . , an are pairwise relatively prime if gcd(ai , aj ) = 1
whenever 1 ≤ i < j ≤ n.

What is the greatest common divisor of 17 and 22?


The integers 17 and 22 have no positive common divisors other than
1, so that gcd(17, 22) = 1.
The integers 17 and 22 are relatively prime, because gcd(17, 22) = 1.
10, 17, and 21 are pairwise relatively prime. 10, 19, and 24 are not
pairwise relatively prime.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 22 / 53


Number Theory Divisibility and Modular Arithmetic

Another way to find the greatest common divisor of two positive integers is
to use the prime factorizations of these integers.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 23 / 53


Number Theory Divisibility and Modular Arithmetic

Another way to find the greatest common divisor of two positive integers is
to use the prime factorizations of these integers.
Suppose that the prime factorizations of the positive integers a and b are

a = p1a1 p2a2 · · · pnan , b = p1b1 p2b2 · · · pnbn ,

where each exponent is a nonnegative integer, and where all primes


occurring in the prime factorization of either a or b are included in both
factorizations, with zero exponents if necessary.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 23 / 53


Number Theory Divisibility and Modular Arithmetic

Another way to find the greatest common divisor of two positive integers is
to use the prime factorizations of these integers.
Suppose that the prime factorizations of the positive integers a and b are

a = p1a1 p2a2 · · · pnan , b = p1b1 p2b2 · · · pnbn ,

where each exponent is a nonnegative integer, and where all primes


occurring in the prime factorization of either a or b are included in both
factorizations, with zero exponents if necessary.
Then gcd(a, b) is given by
min(a1 ,b1 ) min(a2 ,b2 )
gcd(a, b) = p1 · p2 · · · pnmin(an ,bn ) .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 23 / 53


Number Theory Divisibility and Modular Arithmetic

Another way to find the greatest common divisor of two positive integers is
to use the prime factorizations of these integers.
Suppose that the prime factorizations of the positive integers a and b are

a = p1a1 p2a2 · · · pnan , b = p1b1 p2b2 · · · pnbn ,

where each exponent is a nonnegative integer, and where all primes


occurring in the prime factorization of either a or b are included in both
factorizations, with zero exponents if necessary.
Then gcd(a, b) is given by
min(a1 ,b1 ) min(a2 ,b2 )
gcd(a, b) = p1 · p2 · · · pnmin(an ,bn ) .

Because the prime factorizations of 120 and 500 are


120 = 23 · 3 · 5, 500 = 22 · 53 , the greatest common divisor is

gcd(120, 500) = 2min(3,2) · 3min(1,0) · 5min(1,3) = 22 · 30 · 51 = 20.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 23 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The least common multiple of the positive integers a and b is the
smallest positive integer that is divisible by both a and b. The least
common multiple of a and b is denoted by lcm(a, b).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 24 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The least common multiple of the positive integers a and b is the
smallest positive integer that is divisible by both a and b. The least
common multiple of a and b is denoted by lcm(a, b).

Suppose that the prime factorizations of a and b are as before. Then


the least common multiple of a and b is given by
max(a1 ,b1 ) max(a2 ,b2 ) max(an ,bn )
lcm(a, b) = p1 · p2 · · · pn .

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 24 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The least common multiple of the positive integers a and b is the
smallest positive integer that is divisible by both a and b. The least
common multiple of a and b is denoted by lcm(a, b).

Suppose that the prime factorizations of a and b are as before. Then


the least common multiple of a and b is given by
max(a1 ,b1 ) max(a2 ,b2 ) max(an ,bn )
lcm(a, b) = p1 · p2 · · · pn .

What is the least common multiple of 23 35 72 and 24 33 ?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 24 / 53


Number Theory Divisibility and Modular Arithmetic

Definition
The least common multiple of the positive integers a and b is the
smallest positive integer that is divisible by both a and b. The least
common multiple of a and b is denoted by lcm(a, b).

Suppose that the prime factorizations of a and b are as before. Then


the least common multiple of a and b is given by
max(a1 ,b1 ) max(a2 ,b2 ) max(an ,bn )
lcm(a, b) = p1 · p2 · · · pn .

What is the least common multiple of 23 35 72 and 24 33 ?

lcm(23 35 72 , 24 33 ) = 2max(3,4) ·3max(5,3) ·7max(2,0) = 24 ·35 ·72 = 243572.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 24 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let a and b be positive integers. Then

ab = gcd(a, b) · lcm(a, b).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 25 / 53


Number Theory Divisibility and Modular Arithmetic

The Euclidean Algorithm

Computing the greatest common divisor of two integers directly from


the prime factorizations of these integers is inefficient.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 26 / 53


Number Theory Divisibility and Modular Arithmetic

The Euclidean Algorithm

Computing the greatest common divisor of two integers directly from


the prime factorizations of these integers is inefficient.
The reason is that it is time-consuming to find prime factorizations.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 26 / 53


Number Theory Divisibility and Modular Arithmetic

The Euclidean Algorithm

Computing the greatest common divisor of two integers directly from


the prime factorizations of these integers is inefficient.
The reason is that it is time-consuming to find prime factorizations.
We will give a more efficient method of finding the greatest common
divisor, called the Euclidean algorithm.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 26 / 53


Number Theory Divisibility and Modular Arithmetic

Before describing the Euclidean algorithm, we will show how it is used


to find gcd(91, 287).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 27 / 53


Number Theory Divisibility and Modular Arithmetic

Before describing the Euclidean algorithm, we will show how it is used


to find gcd(91, 287).
First, divide 287 by 91, to obtain:

287 = 91 · 3 + 14

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 27 / 53


Number Theory Divisibility and Modular Arithmetic

Before describing the Euclidean algorithm, we will show how it is used


to find gcd(91, 287).
First, divide 287 by 91, to obtain:

287 = 91 · 3 + 14

Any divisor of 91 and 287 must also be a divisor of 287 − 91 · 3 = 14.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 27 / 53


Number Theory Divisibility and Modular Arithmetic

Before describing the Euclidean algorithm, we will show how it is used


to find gcd(91, 287).
First, divide 287 by 91, to obtain:

287 = 91 · 3 + 14

Any divisor of 91 and 287 must also be a divisor of 287 − 91 · 3 = 14.


Any divisor of 91 and 14 must also be a divisor of 287 = 91 · 3 + 14.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 27 / 53


Number Theory Divisibility and Modular Arithmetic

Before describing the Euclidean algorithm, we will show how it is used


to find gcd(91, 287).
First, divide 287 by 91, to obtain:

287 = 91 · 3 + 14

Any divisor of 91 and 287 must also be a divisor of 287 − 91 · 3 = 14.


Any divisor of 91 and 14 must also be a divisor of 287 = 91 · 3 + 14.
Hence, the greatest common divisor of 91 and 287 is the same as the
greatest common divisor of 91 and 14.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 27 / 53


Number Theory Divisibility and Modular Arithmetic

Before describing the Euclidean algorithm, we will show how it is used


to find gcd(91, 287).
First, divide 287 by 91, to obtain:

287 = 91 · 3 + 14

Any divisor of 91 and 287 must also be a divisor of 287 − 91 · 3 = 14.


Any divisor of 91 and 14 must also be a divisor of 287 = 91 · 3 + 14.
Hence, the greatest common divisor of 91 and 287 is the same as the
greatest common divisor of 91 and 14.
This means that the problem of finding gcd(91, 287) has been
reduced to the problem of finding gcd(91, 14).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 27 / 53


Number Theory Divisibility and Modular Arithmetic

Next, divide 91 by 14 to obtain:

91 = 14 · 6 + 7

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 28 / 53


Number Theory Divisibility and Modular Arithmetic

Next, divide 91 by 14 to obtain:

91 = 14 · 6 + 7

Because any common divisor of 91 and 14 also divides


91 − 14 · 6 = 7, and any common divisor of 14 and 7 divides 91, it
follows that gcd(91, 14) = gcd(14, 7).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 28 / 53


Number Theory Divisibility and Modular Arithmetic

Next, divide 91 by 14 to obtain:

91 = 14 · 6 + 7

Because any common divisor of 91 and 14 also divides


91 − 14 · 6 = 7, and any common divisor of 14 and 7 divides 91, it
follows that gcd(91, 14) = gcd(14, 7).
Continue by dividing 14 by 7 to obtain:

14 = 7 · 2

Because 7 | 14, it follows that gcd(14, 7) = 7. Furthermore, because

gcd(287, 91) = gcd(91, 14) = gcd(14, 7) = 7,

the original problem has been solved.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 28 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm

Lemma
Let a = bq + r , where a, b, q, and r are integers. Then gcd(a, b) =
gcd(b, r ).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 29 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm

Lemma
Let a = bq + r , where a, b, q, and r are integers. Then gcd(a, b) =
gcd(b, r ).

Suppose that a and b are positive integers with a ≥ b. Let r0 = a and


r1 = b. When we successively apply the division algorithm, we obtain:

r0 = r1 q1 + r2 , 0 ≤ r2 < r1
r1 = r2 q2 + r3 , 0 ≤ r3 < r2
..
.
rn−2 = rn−1 qn−1 + rn , 0 ≤ rn < rn−1
rn−1 = rn qn

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 29 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm
Divide the greater number by smaller one.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 30 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm
Divide the greater number by smaller one.
If the remainder is 0, GCD is the smaller number.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 30 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm
Divide the greater number by smaller one.
If the remainder is 0, GCD is the smaller number.
Otherwise, divisor is divided by the remainder and this process
continues until obtaining 0 as the remainder.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 30 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm
Divide the greater number by smaller one.
If the remainder is 0, GCD is the smaller number.
Otherwise, divisor is divided by the remainder and this process
continues until obtaining 0 as the remainder.
The previous remainder before 0 is GCD.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 30 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm
Divide the greater number by smaller one.
If the remainder is 0, GCD is the smaller number.
Otherwise, divisor is divided by the remainder and this process
continues until obtaining 0 as the remainder.
The previous remainder before 0 is GCD.
Let us find the gcd(748,2024)

2024 = 748 · 2 + 528


748 = 528 · 1 + 220
528 = 220 · 2 + 88
220 = 88 · 2 + 44
88 = 44 · 2 + 0

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 30 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm
Divide the greater number by smaller one.
If the remainder is 0, GCD is the smaller number.
Otherwise, divisor is divided by the remainder and this process
continues until obtaining 0 as the remainder.
The previous remainder before 0 is GCD.
Let us find the gcd(748,2024)

2024 = 748 · 2 + 528


748 = 528 · 1 + 220
528 = 220 · 2 + 88
220 = 88 · 2 + 44
88 = 44 · 2 + 0

Thus we have gcd(748, 2024) = 44

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 30 / 53


Number Theory Divisibility and Modular Arithmetic

The Euclidean Algorithm

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 31 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm Example


Find the gcd of 414 and 662 using the Euclidean algorithm

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 32 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm Example


Find the gcd of 414 and 662 using the Euclidean algorithm

662 = 414 · 1 + 248


414 = 248 · 1 + 166
248 = 166 · 1 + 82
166 = 82 · 2 + 2
82 = 2 · 41

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 32 / 53


Number Theory Divisibility and Modular Arithmetic

Euclidean Algorithm Example


Find the gcd of 414 and 662 using the Euclidean algorithm

662 = 414 · 1 + 248


414 = 248 · 1 + 166
248 = 166 · 1 + 82
166 = 82 · 2 + 2
82 = 2 · 41

We summarize these steps

j rj rj+1 qj+1 rj+2


0 662 414 1 248
1 414 248 1 166
2 248 166 1 82
3 166 82 2 2
4 82 2 41 0

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 32 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem (Bézout’s Theorem)


If a and b are positive integers, then there exist integers s and t such that
gcd(a, b) = sa + tb.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 33 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem (Bézout’s Theorem)


If a and b are positive integers, then there exist integers s and t such that
gcd(a, b) = sa + tb.

We will present two different methods that can be used to find a linear
combination of two integers equal to their greatest common divisor.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 33 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem (Bézout’s Theorem)


If a and b are positive integers, then there exist integers s and t such that
gcd(a, b) = sa + tb.

We will present two different methods that can be used to find a linear
combination of two integers equal to their greatest common divisor.
The first method proceeds by working backward through the divisions
of the Euclidean algorithm. We will illustrate how this method works
with an example.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 33 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem (Bézout’s Theorem)


If a and b are positive integers, then there exist integers s and t such that
gcd(a, b) = sa + tb.

We will present two different methods that can be used to find a linear
combination of two integers equal to their greatest common divisor.
The first method proceeds by working backward through the divisions
of the Euclidean algorithm. We will illustrate how this method works
with an example.
So this method requires a forward pass and a backward pass through
the steps of the Euclidean algorithm.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 33 / 53


Number Theory Divisibility and Modular Arithmetic

Express gcd(252, 198) = 18 as a linear combination of 252 and 198 by


working backwards through the steps of the Euclidean algorithm.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 34 / 53


Number Theory Divisibility and Modular Arithmetic

Express gcd(252, 198) = 18 as a linear combination of 252 and 198 by


working backwards through the steps of the Euclidean algorithm.
252 = 198 · 1 + 54
198 = 54 · 3 + 36
54 = 36 · 1 + 18
36 = 18 · 2 + 0

Now let’s go backward!


18 = 54 − 1 · 36
18 = 54 − 1 · (198 − 3 · 54)
18 = 4 · 54 − 1 · 198
18 = 4 · (252 − 1 · 198) − 1 · 198
18 = 4 · 252 − 5 · 198

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 34 / 53


Number Theory Divisibility and Modular Arithmetic

Lemma
If a, b, and c are positive integers s.t. gcd(a, b) = 1 and a | bc, then a | c.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 35 / 53


Number Theory Divisibility and Modular Arithmetic

Lemma
If a, b, and c are positive integers s.t. gcd(a, b) = 1 and a | bc, then a | c.

Lemma
If p is a prime and p | a1 a2 · · · an , where each ai ∈ Z, then p | ai for some i.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 35 / 53


Number Theory Divisibility and Modular Arithmetic

Lemma
If a, b, and c are positive integers s.t. gcd(a, b) = 1 and a | bc, then a | c.

Lemma
If p is a prime and p | a1 a2 · · · an , where each ai ∈ Z, then p | ai for some i.

Theorem
Let m be a positive integer and let a, b, and c be integers. If ac ≡ bc
(mod m) and gcd(c, m) = 1, then a ≡ b (mod m).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 35 / 53


Number Theory Divisibility and Modular Arithmetic

Lemma
If a, b, and c are positive integers s.t. gcd(a, b) = 1 and a | bc, then a | c.

Lemma
If p is a prime and p | a1 a2 · · · an , where each ai ∈ Z, then p | ai for some i.

Theorem
Let m be a positive integer and let a, b, and c be integers. If ac ≡ bc
(mod m) and gcd(c, m) = 1, then a ≡ b (mod m).

The congruence 14 ≡ 8 (mod 6) holds, but both sides of this


congruence cannot be divided by 2 to produce a valid congruence
because 7 ̸≡ 4 (mod 6).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 35 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
If a and m are relatively prime integers and m > 1, then an inverse of a
modulo m exists. Furthermore, this inverse is unique modulo m.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 36 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
If a and m are relatively prime integers and m > 1, then an inverse of a
modulo m exists. Furthermore, this inverse is unique modulo m.

Find an inverse of 3 modulo 7 by finding Bézout coefficients.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 36 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
If a and m are relatively prime integers and m > 1, then an inverse of a
modulo m exists. Furthermore, this inverse is unique modulo m.

Find an inverse of 3 modulo 7 by finding Bézout coefficients.


Find an inverse of 101 modulo 4620.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 36 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
If a and m are relatively prime integers and m > 1, then an inverse of a
modulo m exists. Furthermore, this inverse is unique modulo m.

Find an inverse of 3 modulo 7 by finding Bézout coefficients.


Find an inverse of 101 modulo 4620.
What are the solutions of the linear congruence 3x ≡ 4 (mod 7)?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 36 / 53


Number Theory Divisibility and Modular Arithmetic

In the first century, the Chinese mathematician Sun-Tsu asked:

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 37 / 53


Number Theory Divisibility and Modular Arithmetic

In the first century, the Chinese mathematician Sun-Tsu asked:


There are certain things whose number is unknown. When divided by
3, the remainder is 2; when divided by 5, the remainder is 3; and when
divided by 7, the remainder is 2. What will be the number of things?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 37 / 53


Number Theory Divisibility and Modular Arithmetic

In the first century, the Chinese mathematician Sun-Tsu asked:


There are certain things whose number is unknown. When divided by
3, the remainder is 2; when divided by 5, the remainder is 3; and when
divided by 7, the remainder is 2. What will be the number of things?
This puzzle can be translated into the following question: What are
the solutions of the systems of congruences

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 37 / 53


Number Theory Divisibility and Modular Arithmetic

In the first century, the Chinese mathematician Sun-Tsu asked:


There are certain things whose number is unknown. When divided by
3, the remainder is 2; when divided by 5, the remainder is 3; and when
divided by 7, the remainder is 2. What will be the number of things?
This puzzle can be translated into the following question: What are
the solutions of the systems of congruences

x ≡2 (mod 3),
x ≡3 (mod 5),
x ≡2 (mod 7)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 37 / 53


Number Theory Divisibility and Modular Arithmetic

Theorem
Let m1 , m2 , . . . , mn be pairwise relatively prime positive integers greater
than one and a1 , a2 , . . . , an arbitrary integers. Then the system

x ≡ a1 (mod m1 ),
x ≡ a2 (mod m2 ),
..
.
x ≡ an (mod mn )

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

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 38 / 53


Number Theory Divisibility and Modular Arithmetic

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

ap−1 ≡ 1 (mod p).

Furthermore, for every integer a we have

ap ≡ a (mod p).

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 39 / 53


Number Theory Divisibility and Modular Arithmetic

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

ap−1 ≡ 1 (mod p).

Furthermore, for every integer a we have

ap ≡ a (mod p).

p = 15485863 is prime, so Fermat’s little theorem tells us that

215485862 ≡ 1 (mod 15485863)

Thus without doing any computing, we know that the number


215485862 − 1 a number having more than two million digits, is a
multiple of 15485863.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 39 / 53


Number Theory Divisibility and Modular Arithmetic

Find 7222 mod 11

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 40 / 53


Number Theory Divisibility and Modular Arithmetic

Find 7222 mod 11


7222 = 722·10+2 = (710 )22 72 ≡ (1)22 · 49 ≡ 5 (mod 11)
Find 151905 mod 17

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 40 / 53


Number Theory Divisibility and Modular Arithmetic

Fermat’s Little Theorem and Primality

Consider the number m = 15485207. Using the powering algorithm,


it is not hard to compute (on a computer)

2m−1 = 215485206 ≡ 4136685 (mod 15485207)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 41 / 53


Number Theory Divisibility and Modular Arithmetic

Fermat’s Little Theorem and Primality

Consider the number m = 15485207. Using the powering algorithm,


it is not hard to compute (on a computer)

2m−1 = 215485206 ≡ 4136685 (mod 15485207)

We did not get the value 1, so it seems that Fermat’s little theorem is
not true for m. If m were prime, Fermat’s little theorem says that we
would obtained 1. Hence the number m = 15485207 is not prime.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 41 / 53


Number Theory Divisibility and Modular Arithmetic

Fermat’s Little Theorem and Primality

Consider the number m = 15485207. Using the powering algorithm,


it is not hard to compute (on a computer)

2m−1 = 215485206 ≡ 4136685 (mod 15485207)

We did not get the value 1, so it seems that Fermat’s little theorem is
not true for m. If m were prime, Fermat’s little theorem says that we
would obtained 1. Hence the number m = 15485207 is not prime.
It’s actually a bit astonishing. By a simple computation, we have
conclusively proven that m is not prime, yet we do not know any of
its factors!

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 41 / 53


Number Theory Divisibility and Modular Arithmetic

Primality Testing

Is n = 31987937737479355332620068643713101490952335301 a
prime number?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 42 / 53


Number Theory Divisibility and Modular Arithmetic

Primality Testing

Is n = 31987937737479355332620068643713101490952335301 a
prime number?
n is not divisible by any primes smaller than 106 . So we begin to
suspect that maybe n is prime ??

2n−1 ≡1281265953551359064133601216247151836053160074 (mod n)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 42 / 53


Number Theory Divisibility and Modular Arithmetic

Primality Testing

Is n = 31987937737479355332620068643713101490952335301 a
prime number?
n is not divisible by any primes smaller than 106 . So we begin to
suspect that maybe n is prime ??

2n−1 ≡1281265953551359064133601216247151836053160074 (mod n)

n is a composite number, although it does not give us any indication


of how to factor n.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 42 / 53


Number Theory Divisibility and Modular Arithmetic

Primality Testing

Is n = 31987937737479355332620068643713101490952335301 a
prime number?
n is not divisible by any primes smaller than 106 . So we begin to
suspect that maybe n is prime ??

2n−1 ≡1281265953551359064133601216247151836053160074 (mod n)

n is a composite number, although it does not give us any indication


of how to factor n.
Recall Fermat’s little theorem, which says that if p is prime, then

ap−1 ≡ 1 (mod p)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 42 / 53


Number Theory Divisibility and Modular Arithmetic

Is n = 2967952985951692762820418740138329004315165131 prime?

2n ≡ 2 (mod n)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 43 / 53


Number Theory Divisibility and Modular Arithmetic

Is n = 2967952985951692762820418740138329004315165131 prime?

2n ≡ 2 (mod n)

Does it combined with Fermat’s little theorem prove that n is prime?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 43 / 53


Number Theory Divisibility and Modular Arithmetic

Is n = 2967952985951692762820418740138329004315165131 prime?

2n ≡ 2 (mod n)

Does it combined with Fermat’s little theorem prove that n is prime?


The answer is NO! Fermat’s theorem works in only one direction:

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 43 / 53


Number Theory Divisibility and Modular Arithmetic

Is n = 2967952985951692762820418740138329004315165131 prime?

2n ≡ 2 (mod n)

Does it combined with Fermat’s little theorem prove that n is prime?


The answer is NO! Fermat’s theorem works in only one direction:

If p is prime, then ap ≡ a (mod p).

There is nothing to prevent an equality such as 2n ≡ 2 (mod n) being


true for composite values of n, indeed

2341 ≡ 2 (mod 341) with 341 = 11 · 31

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 43 / 53


Number Theory Divisibility and Modular Arithmetic

Is n = 2967952985951692762820418740138329004315165131 prime?

2n ≡ 2 (mod n)

Does it combined with Fermat’s little theorem prove that n is prime?


The answer is NO! Fermat’s theorem works in only one direction:

If p is prime, then ap ≡ a (mod p).

There is nothing to prevent an equality such as 2n ≡ 2 (mod n) being


true for composite values of n, indeed

2341 ≡ 2 (mod 341) with 341 = 11 · 31

Still we may expect that n would be a prime.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 43 / 53


Number Theory Divisibility and Modular Arithmetic

Carmichael Numbers

Definition
Fix an integer n. We say that an integer a is a witness for (compositeness
of) n if
an ̸≡ a (mod n)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 44 / 53


Number Theory Divisibility and Modular Arithmetic

Carmichael Numbers

Definition
Fix an integer n. We say that an integer a is a witness for (compositeness
of) n if
an ̸≡ a (mod n)

A single witness for n combined with Fermat’s little theorem is


enough to prove that n is composite.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 44 / 53


Number Theory Divisibility and Modular Arithmetic

Carmichael Numbers

Definition
Fix an integer n. We say that an integer a is a witness for (compositeness
of) n if
an ̸≡ a (mod n)

A single witness for n combined with Fermat’s little theorem is


enough to prove that n is composite.
Unfortunately, there are some numbers which are not prime although
they have no witness as 561.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 44 / 53


Number Theory Divisibility and Modular Arithmetic

Carmichael Numbers

Definition
Fix an integer n. We say that an integer a is a witness for (compositeness
of) n if
an ̸≡ a (mod n)

A single witness for n combined with Fermat’s little theorem is


enough to prove that n is composite.
Unfortunately, there are some numbers which are not prime although
they have no witness as 561.
The number 561 is composite, 561 = 3 · 11 · 17, yet 561 has no
witnesses! In other words

a561 ≡ a (mod 561) for every integer a.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 44 / 53


Number Theory Divisibility and Modular Arithmetic

Carmichael Numbers

Definition
Fix an integer n. We say that an integer a is a witness for (compositeness
of) n if
an ̸≡ a (mod n)

A single witness for n combined with Fermat’s little theorem is


enough to prove that n is composite.
Unfortunately, there are some numbers which are not prime although
they have no witness as 561.
The number 561 is composite, 561 = 3 · 11 · 17, yet 561 has no
witnesses! In other words

a561 ≡ a (mod 561) for every integer a.

Composite numbers having no witness are called Carmichael numbers.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 44 / 53


Number Theory Divisibility and Modular Arithmetic

Finding Multiplicative Inverse via Fermat’s Little Theorem

Fermat’s little theorem and the fast powering algorithm provide us


with a reasonably efficient method of computing inverses modulo p,
namely
a−1 ≡ ap−2 (mod p)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 45 / 53


Number Theory Divisibility and Modular Arithmetic

Finding Multiplicative Inverse via Fermat’s Little Theorem

Fermat’s little theorem and the fast powering algorithm provide us


with a reasonably efficient method of computing inverses modulo p,
namely
a−1 ≡ ap−2 (mod p)
We compute the inverse of 7814 modulo 17449 in two ways. First,

7814−1 ≡ 781417447 ≡ 1284 (mod 17449)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 45 / 53


Number Theory Divisibility and Modular Arithmetic

Finding Multiplicative Inverse via Fermat’s Little Theorem

Fermat’s little theorem and the fast powering algorithm provide us


with a reasonably efficient method of computing inverses modulo p,
namely
a−1 ≡ ap−2 (mod p)
We compute the inverse of 7814 modulo 17449 in two ways. First,

7814−1 ≡ 781417447 ≡ 1284 (mod 17449)

Second, we use the extended Euclidean algorithm to obtain

7814 · 1284 + 17449 · (−575) = 1

So, 7814−1 ≡ 1284 (mod 17449)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 45 / 53


Number Theory Divisibility and Modular Arithmetic

Check Digits

Congruences are used to check for errors in digit strings.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 46 / 53


Number Theory Divisibility and Modular Arithmetic

Check Digits

Congruences are used to check for errors in digit strings.


A common technique for detecting or correcting errors in such strings
is to add an extra digit (or digits) at the end of the string.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 46 / 53


Number Theory Divisibility and Modular Arithmetic

Check Digits

Congruences are used to check for errors in digit strings.


A common technique for detecting or correcting errors in such strings
is to add an extra digit (or digits) at the end of the string.
This final digit, or check digit, is calculated using a particular
function. Then, to determine whether a digit string is correct, a check
is made to see whether this final digit has the correct value.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 46 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Assume that we want to transmit some information over a


transmission channel by using 0’s and 1’s.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 47 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Assume that we want to transmit some information over a


transmission channel by using 0’s and 1’s.
Right ↔ 00, Left ↔ 01, Up ↔ 10, Down ↔ 11

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 47 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Assume that we want to transmit some information over a


transmission channel by using 0’s and 1’s.
Right ↔ 00, Left ↔ 01, Up ↔ 10, Down ↔ 11
Let us send Right ↔ 00

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 47 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Assume that we want to transmit some information over a


transmission channel by using 0’s and 1’s.
Right ↔ 00, Left ↔ 01, Up ↔ 10, Down ↔ 11
Let us send Right ↔ 00
Suppose an error occured while transmission due to noise.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 47 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Assume that we want to transmit some information over a


transmission channel by using 0’s and 1’s.
Right ↔ 00, Left ↔ 01, Up ↔ 10, Down ↔ 11
Let us send Right ↔ 00
Suppose an error occured while transmission due to noise.
error
Right ↔ 00 −−−→ 10 ↔ Up.

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 47 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Assume that we want to transmit some information over a


transmission channel by using 0’s and 1’s.
Right ↔ 00, Left ↔ 01, Up ↔ 10, Down ↔ 11
Let us send Right ↔ 00
Suppose an error occured while transmission due to noise.
error
Right ↔ 00 −−−→ 10 ↔ Up.
Is it possible to correct the error, or at least detect?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 47 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Code the message x1 x2 to x1 x2 x3 where x3 = x1 + x2 mod 2

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 48 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Code the message x1 x2 to x1 x2 x3 where x3 = x1 + x2 mod 2


00→ 000, 01→ 011, 10 → 101, 11→ 110

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 48 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Code the message x1 x2 to x1 x2 x3 where x3 = x1 + x2 mod 2


00→ 000, 01→ 011, 10 → 101, 11→ 110
Can we detect if an error has occurred?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 48 / 53


Number Theory Divisibility and Modular Arithmetic

Why do we use Check Digits

Code the message x1 x2 to x1 x2 x3 where x3 = x1 + x2 mod 2


00→ 000, 01→ 011, 10 → 101, 11→ 110
Can we detect if an error has occurred?
Can we correct if an error has occurred?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 48 / 53


Number Theory Divisibility and Modular Arithmetic

Check Digits

International Article Number, also known as European Article


Number (EAN), is a global standard that defines a barcode format
and a unique numbering system used in retail and trade.
It helps identify specific types of retail products based on their
packaging and manufacturer, making it easier to track and manage
products across international supply chains.
The most widely used version is EAN-13, a thirteen-digit format that
evolved from the earlier 12-digit Universal Product Code (UPC-A).
ISBN-13 check digit calculation is the same

x1 +3x2 +x3 +3x4 +x5 +3x6 +x7 +3x8 +x9 +3x10 +x11 +3x12 +x13 ≡0 (mod 10)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 49 / 53


Number Theory Divisibility and Modular Arithmetic

Check Digits

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 50 / 53


Number Theory Divisibility and Modular Arithmetic

Turkish Republic Identification Numbers have also check digits

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11

where

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 51 / 53


Number Theory Divisibility and Modular Arithmetic

Turkish Republic Identification Numbers have also check digits

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11

where

x10 = 7x1 − x2 + 7x3 − x4 + 7x5 − x6 + 7x7 − x8 + 7x9 (mod 10)

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 51 / 53


Number Theory Divisibility and Modular Arithmetic

Turkish Republic Identification Numbers have also check digits

x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11

where

x10 = 7x1 − x2 + 7x3 − x4 + 7x5 − x6 + 7x7 − x8 + 7x9 (mod 10)


x11 = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 (mod 10)
Can we write it as a matrix multiplication?

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 51 / 53


Number Theory Divisibility and Modular Arithmetic

TC ID Numbers Coding

7 8
 

 9 0 


 7 8 


 9 0 

 I9×9
(x1 x2 x3 x4 x5 x6 x7 x8 x9 )  7 8  = (x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 )


 9 0 


 7 8 

 9 0 
7 8

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 52 / 53


References

References

Kenneth Rosen, Discrete Mathematics and Its Applications, 8th


edition, McGraw-Hill Education, 2019.
to be updated

Fatih Temiz, PhD (Üsküdar University) Discrete Mathematics Spring 2024-2025 53 / 53

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