You are on page 1of 58

Integer • Introduction

• Modular
Arithmetic
• GCD, LCM
CSCI 1303 • Number systems
Mathematics for Computing I
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Greatest Common Divisor (GCD)


• the largest positive integer that divides each
of given integers
• also known as:
• greatest common factor (gcf)
• highest common factor (hcf)
• greatest common measure (gcm)
• highest common divisor
https://en.wikipedia.org/wiki/Greatest_common_divisor
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Greatest Common Divisor (GCD)


+
• If 𝑎, 𝑏 and 𝑘 are in ℤ , and 𝑘|𝑎 and 𝑘|𝑏,
then 𝑘 is a common divisor of 𝑎 and 𝑏
• If 𝑑 is the largest such 𝑘, 𝑑 is called the
greatest common divisor of 𝑎 and 𝑏, and
we write 𝑑 = gcd(𝑎, 𝑏)

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Techniques to Calculate GCD


GCD can be
1. Brute force Calculated using 3
2. Prime factorization techniques
3. Euclidean algorithm

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Calculate 𝐺𝐶𝐷(92, 132)
List all possible factors:
Brute force:
1. List all possible factors of given
numbers
2. manually select the correct GCD

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Techniques to Calculate GCD

1 Brute force Exhaustive. List all possible


divisors, and manually select
the correct one
2 Euclidean algorithm Remainder analysis
3 Prime factorization Use prime factors

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Techniques to Calculate GCD

1 Brute force Exhaustive. List all possible


divisors, and manually select
the correct one
2 Euclidean algorithm Remainder analysis
3 Prime factorization Use prime factors

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Brute force

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Calculate 𝐺𝐶𝐷(92, 132)

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Calculate 𝐺𝐶𝐷(92, 132)
List all possible factors of 92 and 132:

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Calculate 𝐺𝐶𝐷(92, 132)
List all possible factors of 92 and 132:
92 = 1 ∙ 92
= 2 ∙ 46
= 4 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Calculate 𝐺𝐶𝐷(92, 132)
List all possible factors of 92 and 132:
92 = 1 ∙ 92
= 2 ∙ 46
= 4 ∙ 23

Factors of 92 are
1, 2, 4, 23, 46 and 92
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Calculate 𝐺𝐶𝐷(92, 132)
List all possible factors of 92 and 132:
92 = 1 ∙ 92 132 = 1 ∙ 132
= 2 ∙ 46 132 = 2 ∙ 66
= 4 ∙ 23 132 = 3 ∙ 44
132 = 4 ∙ 33
Factors of 92 are 132 = 6 ∙ 22
1, 2, 4, 23, 46 and 92 132 = 11 ∙ 12
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force Factors of 132 are


1, 2, 3, 4, 6, 11, 12,
Calculate 𝐺𝐶𝐷(92, 132) 22, 33, 44, 66 and
List all possible factors of 92 and 132: 1322
92 = 1 ∙ 92 132 = 1 ∙ 132
= 2 ∙ 46 132 = 2 ∙ 66
= 4 ∙ 23 132 = 3 ∙ 44
132 = 4 ∙ 33
Factors of 92 are 132 = 6 ∙ 22
1, 2, 4, 23, 46 and 92 132 = 11 ∙ 12
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


Common factors of
Calculate 𝐺𝐶𝐷(92, 132) 92 and 132 are:
2 and 4
List all possible factors of 92 and 132:
92 = 1 ∙ 92 132 = 1 ∙ 132
= 2 ∙ 46 132 = 2 ∙ 66
= 4 ∙ 23 132 = 3 ∙ 44
132 = 4 ∙ 33
132 = 6 ∙ 22
132 = 11 ∙ 12
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Brute force


The Greatest
Common factor of
Calculate 𝐺𝐶𝐷(92, 132)
92 and 132 is
List all possible factors of 92 and 132:
4
92 = 1 ∙ 92 132 = 1 ∙ 132
= 2 ∙ 46 132 = 2 ∙ 66
= 4 ∙ 23 132 = 3 ∙ 44
132 = 4 ∙ 33
132 = 6 ∙ 22
132 = 11 ∙ 12 𝐺𝐶𝐷(92, 132) = 4
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Euclidean Algorithm

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Euclidean algorithm
Calculate 𝒈𝒄𝒅 𝒂, 𝒃

divide 𝒂 by 𝒃: 𝒂 = 𝒒𝟏 𝒃 + 𝒓𝟏 𝟎 ≤ 𝒓𝟏 < 𝒃
divide 𝒃 by 𝒓𝟏 : 𝒃 = 𝒒𝟐 𝒓𝟏 + 𝒓𝟐 𝟎 ≤ 𝒓𝟐 < 𝒓𝟏
divide 𝐫𝟏 by 𝐫𝟐 : 𝒓𝟏 = 𝒒𝟑 𝒓𝟐 + 𝒓𝟑 𝟎 ≤ 𝒓𝟑 < 𝒓𝟐

divide 𝐫𝐧−𝟐 by 𝐫𝐧−𝟏 : 𝒓𝒏−𝟐 = 𝒒𝒏 𝒓𝒏−𝟏 + 𝒓𝒏 𝟎 ≤ 𝒓𝒏 < 𝒓𝒏−𝟏
divide 𝐫𝐧−𝟏 by 𝐫𝐧 : 𝒓𝒏−𝟏 = 𝒒𝒏+𝟏 𝒓𝒏 + 𝒓𝒏+𝟏 𝒓𝒏+𝟏 = 𝟎

𝒂 > 𝒃 > 𝒓𝟏 > 𝒓𝟐 > 𝒓𝟑 > ⋯ > 𝒓𝒏 > 𝟎


hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒
Since 𝒓𝟑 ≠ 0, proceed

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒
Since 𝒓𝟑 ≠ 0, proceed 𝟏𝟐 = 𝒒𝟒 ∙ 𝟒 + 𝒓𝟒

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒
Since 𝒓𝟑 ≠ 0, proceed 𝟏𝟐 = 𝒒𝟒 ∙ 𝟒 + 𝒓𝟒
Determine 𝒒𝟒 and 𝒓𝟒

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒
Since 𝒓𝟑 ≠ 0, proceed 𝟏𝟐 = 𝒒𝟒 ∙ 𝟒 + 𝒓𝟒
Determine 𝒒𝟒 and 𝒓𝟒 𝟏𝟐 = 𝟑 ∙ 𝟒 + 𝟎

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒
Since 𝒓𝟑 ≠ 0, proceed 𝟏𝟐 = 𝒒𝟒 ∙ 𝟒 + 𝒓𝟒
Determine 𝒒𝟒 and 𝒓𝟒 𝟏𝟐 = 𝟑 ∙ 𝟒 + 𝟎
Since 𝒓𝟒 = 0, STOP

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Euclidean Algorithm

Calculate 𝐺𝐶𝐷(92, 132)


Divide 𝟏𝟑𝟐 by 𝟗𝟐 𝟏𝟑𝟐 = 𝒒𝟏 ∙ 𝟗𝟐 + 𝒓𝟏
𝟏𝟑𝟐 > 𝟗𝟐, so a = 132 and b = 92 Determine 𝒒𝟏 and 𝒓𝟏 𝟏𝟑𝟐 = 𝟏 ∙ 𝟗𝟐 + 𝟒𝟎
Since 𝒓𝟏 ≠ 𝟎, proceed 𝟗𝟐 = 𝒒𝟐 ∙ 𝟒𝟎 + 𝒓𝟐
Determine 𝒒𝟐 and 𝒓𝟐 𝟗𝟐 = 𝟐 ∙ 𝟒𝟎 + 𝟏𝟐
Since 𝒓𝟐 ≠ 𝟎, proceed 𝟒𝟎 = 𝒒𝟑 ∙ 𝟏𝟐 + 𝒓𝟑
Determine 𝒒𝟑 and 𝒓𝟑 𝟒𝟎 = 𝟑 ∙ 𝟏𝟐 + 𝟒
Since 𝒓𝟑 ≠ 0, proceed 𝟏𝟐 = 𝒒𝟒 ∙ 𝟒 + 𝒓𝟒
Determine 𝒒𝟒 and 𝒓𝟒 𝟏𝟐 = 𝟑 ∙ 𝟒 + 𝟎
Since 𝒓𝟒 = 0, STOP 𝐺𝐶𝐷 92, 132 = 4

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Prime Factorization

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐
Prime
factors
2 92

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐
Prime
factors
2 92
46

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐
Prime
factors
2 92
2 46

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐
Prime
factors
2 92
2 46
23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐
Prime
factors
2 92
2 46
23

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 132
2 46
23

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46
23

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46 66
23

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46 2 66
23

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46 2 66
23 33

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46 2 66
23 3 33

92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46 2 66
23 3 33
11
92 = 22 ∙ 23

hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
2 46 2 66
23 3 33
11
92 = 22 ∙ 23
132 = 22 ∙ 31 ∙ 111
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
𝐺𝐶𝐷 92, 132
2 46 2 66
= 2min(2,2) ∙ 3min 0,1 ∙ 11min 0,1 ∙ 23min 1,0
23 3 33 = 22 ∙ 30 ∙ 110 ∙ 230
11 =4
92 = 22 ∙ 23
132 = 22 ∙ 31 ∙ 111
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
𝐺𝐶𝐷 92, 132
2 46 2 66
= 2min(2,2) ∙ 3min 0,1 ∙ 11min 0,1 ∙ 23min 1,0
23 3 33 = 22 ∙ 30 ∙ 110 ∙ 230
11 =4
92 = 22 ∙ 23
132 = 22 ∙ 31 ∙ 111
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
𝐺𝐶𝐷 92, 132
2 46 2 66
= 2min(2,2) ∙ 3min 0,1 ∙ 11min 0,1 ∙ 23min 1,0
23 3 33 = 22 ∙ 30 ∙ 110 ∙ 230
11 =4
92 = 22 ∙ 23
132 = 22 ∙ 31 ∙ 111
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
𝐺𝐶𝐷 92, 132
2 46 2 66
= 2min(2,2) ∙ 3min 0,1 ∙ 11min 0,1 ∙ 23min 1,0
23 3 33 = 22 ∙ 30 ∙ 110 ∙ 230
11 =4
92 = 22 ∙ 23
132 = 22 ∙ 31 ∙ 111
hyaacob@iium.edu.my
CSCI1303 - Mathematics for Computing I Integer – GCD/LCM

Calculate GCD: Prime factorization


Calculate 𝐺𝐶𝐷(92, 132)
Calculate prime factors for 𝟗𝟐 and 𝟏𝟑𝟐
Prime Prime
factors factors
2 92 2 132
𝐺𝐶𝐷 92, 132
2 46 2 66
= 2min(2,2) ∙ 3min 0,1 ∙ 11min 0,1 ∙ 23min 1,0
23 3 33 = 22 ∙ 30 ∙ 110 ∙ 230
11 =4
92 = 22 ∙ 23
132 = 22 ∙ 31 ∙ 111
hyaacob@iium.edu.my

You might also like