Lecture 22 Filled
Lecture 22 Filled
Lecture 22
2024 – 11 – 26
1/19
Some Information
Today:
¶ Objectives for §36:
… GCD.
To do:
¶ Problem set 8
or
¶ Rest a bit
¶ Read §47 by next class and do the pre-lecture quiz.
2/19
Greatest Common Divisor
Definition
Let a and b be integers. We say that an integer d is a common divisor of a and b
if d|a and d|b.
Definition
Let a and b be integers. We say that an integer d is the greatest common divisor
or a and b if
1. d is a common divisor of a and b.
2. If e is a common divisor of a and b, then e Æ d.
We use gcd (a, b) to denote the greatest common divisor of a and b.
¶ gcd(6, 32) = 2
¶ gcd(≠6, ≠32) =
2
2
Find gcd(210, 45) by picking the greatest common divisor.
god 154 77 77
god 154 77 77
bit.ly/F24DML22
gcd 2 4 god 2 4
3/19
Applications
¶ Cryptography
… RSA Algorithm: GCD is used in computing modular inverses and in ensuring
that keys are coprime (i.e., gcd(e, Ï(n)) = 1) in public-key cryptography.
¶ Computer Science
… Algorithms: Data Compression: GCD helps with algorithms like JPEG and
MP3 encoding by simplifying ratios.
… String Matching: Used in problems that involve periodicity and string
rotations.
… Distributed Systems: Helps optimize task scheduling when periodic tasks have
different frequencies.
… Programming: Algorithms often use GCD for optimization problems, such as
determining array rotations or finding grid sizes in graphical applications.
¶ Engineering and Digital Signal Processing
… Signal Resampling: When changing the sampling rate of a signal, GCD is
used to determine the optimal factor for upsampling or downsampling.
… Frequency Matching: Helps find compatible frequencies in systems with
multiple signals.
¶ Geometry
… Grid Problems: GCD is used to find the number of lattice points
(integer-coordinate points) between two points on a line segment.
… Tiling: When tiling a rectangle with square tiles, the size of the largest square
tile is determined using the GCD of the rectangle’s dimensions.
¶ Everyday Applications
… Scheduling: Useful for finding repeating patterns or cycles in schedules.
… Ratios: Simplifies ratios in finance, physics, and chemistry.
¶ Competitive Programming and Puzzles
… GCD is a common component in coding challenges and problems that involve
optimizing or simplifying numerical relations.
4/19
� Given a and b, what’s a reliable way to compute the GCD?
� Assume a > b. How many divisions are needed to execute this algorithm?
107100
Eh 6 perform 2.6 operation
1010 0357872175
1010 0357 8 7 2 17 53
5/19
Computing gcd
gcd a b
Base cases:
Lemma
Let a be a positive integer.
1. gcd(a, 1) = 1
2. gcd(a, 0) = a
3. gcd(a, a) = a
cases 1
11 a clearly
111 clearly
other divison
any of 1 wouldbe 1
no other integer greater than 1 divides 1
2 a 0 a
god
al a obvious
al 0 0 0 a sothis istrue
no other integer greater than a divides a
3 gcd a a a
al a obvious
no other integer greater than a divides a
_0 xe
JIE
integer n divides 0
any
huez 4104
1
6/19
Another Algorithm
a b b c
Proposition
sharing commondivisor
Let a and b be positive integers and let c = a mod b. Then
m aii.at.li
d.a writeT thme
and
q.Famod q.dtistd.k
amodled.to
d q.kz ka
so dla 7/19
3 Since a b and b c share divisors
If a, b, d, x and y are integers, and d|a and d|b, then d|(ax + by). god will be the same
Tame dla and Ttb Then F 6 dke
forsomeki ka EZ
then
axtby d.ki.xtd.kz y 11
An expression of the form ax + by (a sum of multiples) is called a linear
combination.
¶ In the case that c = a mod b, we see that a is a linear combination of b and
c, but also c is a linear combination of a and b.
¶ So any divisor of a and b is a divisor of c.
a1 b
q
8/19
4
Find gcd of 420 and 96.
gcd 420 96
1 T 96 2 96 192 calculations
4 operations using
gcd a 6 god b a mode
16
8 4
21
9/19
Euclid’s algorithm
10/19
Bézout’s identity
Remarks:
¶ the numbers x and y in the equation ax + by = gcd(a, b), are called Bézout
coefficients of a and b. (not in our text)
¶ They are not unique. If (x, y) is one pair, and ae = bf for some e, f , then
(x + e, y ≠ f ) is another pair.
find x
y 6x
6 x 16
Fy T 6 16 2
2
y
6 3 16 1 2
50 3 1 are Bézoutcoff
y
6 02
11/19
Theorem: Bézout’s Identity
Let a and b be integers, not both zero. The smallest positive integer of the form
ax + by, where x and y are integers, is gcd(a, b).
FI
Suppose, for the sake of contradiction, that a is not divisible by d. Then
when we divide a by d, we get a nonzero remainder:
0a
a = qd + r with 0 < r < d.
2
Now d = ax + by, so we can solve for r in terms of a and b as follows: q.d z with
I 0
918 1
r = a ≠ qd = a ≠ q(ax + by) = a(1 ≠ qx) + b(≠qy),
tfy
Suppose e | a and e | b. Then e | (ax + by) (Exercise 5.11). Therefore e | d,
so e Æ d (because d is positive).
contradiction
12/19
ax + by = gcd(a, b)
7
Find integers x and y such that 210x + 45y = 15.
god 210,45
god 45 210mod 45
d
ged 210,45 210 10
31 51
god 45,30
gcd 30,45mod30
1110300 15 45
301g
god 30 15 15 45 1 210
4.45
god 15 30mod 15 30 2.15 0
sedition is
it t
8
5
Let a = 35 and b = 8. Find d = gcd(a, b) and x, y such that ax + by = d.
48t 2
35
III
1s smotsT 3z 2
8 30
god3,2
2 8 2 13518
ftp
god 2,3m.dz 3 2
god 2,1 1 71
35xt8y 1
Definition
Positive integers a and b are called relatively prime if gcd(a, b) = 1.
Note: a single number can’t be relatively prime by itself. Only two numbers can
be relatively prime (relatively means "in relation to each other").
a
Corollary
hand 9
Positive integers a and b are relatively prime iff there exist integers x and y such
that ax + by = 1.
Proposition
_eÉ
Let a and b be integers and d = gcd(a, b). If e is a common divisor of a and b,
then e|d.
b
god a
axiby for
x
some
14/19
Exercise 1
For each pair of integers a and b, find integers x and y such that
ax + by = gcd(a, b).
a) 20, 25
Y f
b) 0, 10
c) ≠89, ≠98
d) 123, ≠123
e) 54321, 50
89 98
y god 89 58 god 89.98
X 11 9889 0.89
9.98
y 10 98 89 10.89
10.98
9 gg
9 54321 6 50 11.82
god 54321,50 1
5 321 1
504 5121 5
16 21 21 54321 50.186
50 2.21
abig 2 8 8 505.25
6 2,92 22
21 2 8 5 5 21 2 8
8 5.1 3 3 8 51
5 3 1 2 2
3 2 1
0 53
15/19
Exercise 2
Suppose a, b, n œ Z with n > 1. Suppose that ab © 1 (mod n). Prove that
both a and b are relatively prime to n.
sina.us
we are gin
byd8
that.gg
soab
fj 1 n.k for some
i e kez
ab n k
so gedla.FI tiMg e
also god b n 1
16/19
Exercise 3
Let a and b be positive integers. Find the sum of all the common divisors of a
and b.
Let E LTI dla and d 6
d 0
E 2 4
Exercise 4
Prove that if a and b have a greatest common divisor, it is unique.
xercise
17/19
Exercise 5
Let a be a positive integer. Prove that 2a + 1 and 4a2 + 1 are relatively prime.
hail
y
ha I_
gcd Jail 4921 by Euclid'salgorithm
18/19
Exercise 6
Suppose a, n œ Z with n > 1. Suppose that a and n are relatively prime. Prove
that there is an integer b such that ab © 1(mod n).
suppose
th.FI sIle E
since
god a n 1 we getthatthere are x y
axtny 1
n i.e.nl
ax 1
ax 1
19/19