0% found this document useful (0 votes)
25 views13 pages

Unit 3. Greatest Common Divisor

The document explains the concept of the greatest common divisor (gcd) of two integers, providing definitions and examples of how to calculate it using various methods, including the Euclidean algorithm. It also discusses the concept of relatively prime integers, where the gcd is 1, and provides exercises to test understanding of these concepts. Additionally, it introduces the extended Euclidean algorithm for finding integers s and t alongside the gcd.

Uploaded by

Chatan Bawankar
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)
25 views13 pages

Unit 3. Greatest Common Divisor

The document explains the concept of the greatest common divisor (gcd) of two integers, providing definitions and examples of how to calculate it using various methods, including the Euclidean algorithm. It also discusses the concept of relatively prime integers, where the gcd is 1, and provides exercises to test understanding of these concepts. Additionally, it introduces the extended Euclidean algorithm for finding integers s and t alongside the gcd.

Uploaded by

Chatan Bawankar
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/ 13

Greatest Common Divisor

• Def: Let a,b be integers, not both zero. The greatest


common divisor of a and b (or gcd(a,b) ) is the biggest number
d which divides both a and b without a remainder

• gcd (8,12) =4

• Find gcd (54, 24)


• 54x1 = 27x2 = 18x3 = 9x6; {1, 2 ,3, 6, 9, 18, 27, 54}
• 24x1 = 12x2 = 8x3 = 4x6; {1, 2 ,3, 4, 6, 8, 12, 24}
• Share number : {1, 2, 3, 6}
• gcd (54, 24) = 6

1
Mr. C. D. Bawankar Department of Information Technology
Greatest Common Divisor
• gcd(a,0) = a, and gcd(a,b) = gcd(b, a mod b)
• a >b , if not then swap and if in gcd(b, a mod b) where
a mob b is zero than stop.
Find gcd(132, 28) :
1. r = 132 mod 28 = 20 => gcd(28, 20)
2. r = 28 mod 20 = 8 => gcd(20,8)
3. r = 20 mod 8 = 4 => gcd(8,4)
4. r = 8 mod 4 = 0 => gcd(4,0)
gcd(132, 28) = 4

1 2 3 4 5
a 132 28 20 8 4
b 28 20 8 4 0

2
Mr. C. D. Bawankar Department of Information Technology
GCD and Relatively Prime
• Def: two integers a and b are said to be relatively prime (also
called co-prime) if gcd(a,b) = 1
• so no prime common divisors.
Find gcd(28, 15) :
1. r = 28 mod 15 = 13 => gcd(15, 13)
2. r = 15 mod 13 = 2 => gcd(13, 2)
3. r = 13 mod 2 = 1 => gcd(2,1)
4. r = 2 mod 1 = 0 => gcd(1,0)
gcd(28,15) = 1

15 and 28 are relative prime

Since a prime number has no factors besides itself, clearly a prime number
is relatively prime to every other number (except for multiples of itself)

3
Mr. C. D. Bawankar Department of Information Technology
Test Relative Prime
Q: Find the following gcd’s:
1. gcd(77,11)
2. gcd(77,33)
3. gcd(36,24)
4. gcd(23,7)

4
Mr. C. D. Bawankar Department of Information Technology
Test Relative Prime
A:
1. gcd(77,11) = 11
2. gcd(77,33) = 11
3. gcd(36, 24) = 12
4. gcd(23,7) = 1. Therefore 23 and 7 are relatively
prime.

Mr. C. D. Bawankar Department of Information Technology


Extended Euclidean Algorithm
Given two integers a and b, we often need to find other two
integers, s and t, such that

The extended Euclidean algorithm can calculate the gcd (a,


b) and at the same time calculate the value of s and t.

2.6
Extended Euclidean algorithm, part a

2.7
Extended Euclidean algorithm, part b

2.8
Example

Given a = 161 and b = 28, find gcd (a, b) and the values of s
and t.

Solution
We get gcd (161, 28) = 7, s = −1 and t = 6.

2.9
Example
Given a = 17 and b = 0, find gcd (a, b) and the values of s
and t.

Solution
We get gcd (17, 0) = 17, s = 1, and t = 0.

2.10
Example

Given a = 0 and b = 45, find gcd (a, b) and the values of s


and t.

Solution
We get gcd (0, 45) = 45, s = 0, and t = 1.

2.11
Example

Given a = 482 and b = 1180, find gcd (a, b) and the values
of s and t.

Solution

q r1 r2 r s1 s2 s t1 t2 T
1 0 0 1

2.12
Given a = 45 and b =13, find gcd (a, b) and the values of s
and t.

Given a = 259 and b = 119, find gcd (a, b) and the values of
s and t.

You might also like