0% found this document useful (0 votes)
11 views19 pages

Lecture 22 Filled

Uploaded by

Joy Song
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)
11 views19 pages

Lecture 22 Filled

Uploaded by

Joy Song
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/ 19

Discrete Mathematics

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.

210 70.21 2 5.3.7


1m
is
5 9 5 3 3.5
Divisors of45 103,150,011 19 1105 45
god 21045 15
154 2 77

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?

Consider the following "brute force" method:


For each k from 1 to the smaller of a and b:
¶ Decide if k is a common divisor of a and b.
¶ If not, discard it.
¶ If yes, save it and discard any lesser common divisors.
When finished, the saved number is 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

gcd(a, b) = gcd(b, c). if dla dlb then dlb.dk


6 Fgcd 6 a mod b
if dlb.de then dla all
when
asb.ge
whattfbsatam.de
Tamodbcbvf
lnampf f aY
sharecommon
divisor
suppose I a and d b
we want to show that then d c as well
we can write a 6 z g
9.6 amol
a mod b a q6
Since dla we can express a d Ki HEI
d 6 we write b d.kz LEE
gan
a mod b dk d.kz d K 9h2
g
since k gkz 72

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.

god a 6 god b a mod b


420 96 god 96 420mod96
gcd 420mod96 36
god 96 36 420 4.96436
god 36 96mod36 96 2.36
249
gcd 36,24 az
36 24 1 12
gcd 24 12
god 12 0 12

Remarks: 1d gadlb amod


¶ The key is that a mod b is smaller than b. So we can work our way down a
chain of remainders.
¶ Compare this to the ’brute force’ algorithm of checking all the numbers
between 1 and 96 to see if they are factors of 96 and factors of 420.

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

Euclid’s gcd algorithm


To compute gcd for given positive integers a and b:
1. Compute c = a mod b.
2. If c = 0, stop. The answer is b.
3. If c > 0, compute gcd(b, c) instead.

This can be shortened to 2 steps:


1. If b = 0, stop. The answer is a.
2. If b > 0, compute gcd(b, a mod b) instead.
5
Find gcd(210, 45) using the Euclidean Algorithm.

gcd 210,45 god 45 210mod 210 445t30


god 45 30
45 30.1 15
god 30 45mod3
god 30 15
god 15 30mod 30 25 0
15 0
god 15

10/19
Bézout’s identity

Theorem: Bézout’s Identity


ax by
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).

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.

T.ee aTly f 6 x.FtIaty.b ft axyb gedla6


6
Find a set of Bézout coefficients for a = 6 and b = 16.

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

1. Let a and b be integers (not both zero) and let

D = {ax + by : x, y œ Z, ax + by > 0}.


__e
2. We want to examine the smallest member of D.
3. First, we must be sure that D is nonempty.
4. To see that D , , we just have to prove that there is at least one integer
in D.
5. Can we select integers x and y to make ax + by positive? If we take x = a
and y = b, we find that
ax + by = a2 + b2 ,
0
and this is positive (unless a = b = 0, which is forbidden by hypothesis).
6. Therefore D , .
7. Applying the Well-Ordering Principle to D, a nonempty set of natural
numbers, we know that D contains a least element; call that least element
d.
8. Our goal is to show that d = gcd(a, b).
9. We need to show three things: (1) d | a, (2) d | b, and (3) if e | a and e | b,
then e Æ d.
10. We do each of these in turn.
¶ Claim (1): d | a.

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),

where X = 1 ≠ qx and Y = ≠qy. Notice that 0 < r < d and r = aX + bY .


2
a
This means that r œ D and r < d, contradicting the fact that d is the least
element of D. Therefore d | a. q axtby
a
¶ Claim (2): d | b.
This proof is analogous to d | a. a.qx gby
299 94
¶ Claim (3): If e | a and e | b, then e Æ d.

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)

¶ How do we find x and y? It’s not obvious.


¶ In the Euclidean Algorithm, we threw away the quotient and kept the
remainder. Here the quotient is actually useful.
¶ As well as the method of back-substitution.

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.

god 35,8 18,35m.at

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

313 105 104


13/19
A Couple More Results

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

gadl89,98 god 89,9 98 89 1 9 g 98 89


god 9,8 89 9.9 8 F
8989 99
ged 8,11 1 9 81 0
9889
89 9.98
9.89
1 9 8.71019 9.18

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

You might also like