gcd

advertisement
Greatest Common Divisor
Definitions
• Let a and b be two non-zero integers. The
greatest common divisor of a and b,
denoted gcd(a,b) is the largest of all
common divisors of a and b.
• When gcd(a,b) = 1, we say that a and b
are relatively prime.
Examples
• gcd(10,25) = 5
• gcd(10,26) = 2
• gcd(10,27) = 1
so 10 and 27 are relatively prime!
• gcd(10,30) = 10
• gcd(-10,-30) = 10
• gcd(13978,15457) = 29
Thm 0.2 GCD is a Linear
Combination
• For any nonzero integers a and b, there
exist integers s and t such that
gcd(a,b) = as + bt
• Moreover, gcd(a,b) is the smallest postive
integer of the form as + bt.
• Note: This is the most important thing to
know about greatest common divisors!
Example
•
•
•
•
gcd(32,14) = 2
Check that 32(-3) + 14(7) = 2
Also, 32(11) + 14(-25) = 2
In fact, there are infinitely many ways to
write 2 as a linear combination.
• 2 is the smallest postive linear combination
of 32 and 14.
• (Also, 2 | 32s + 14t for all integers s, t)
Example
•
•
•
•
gcd(13978,15457) = 29
Check that 13978(209) + 15457(-189) = 29
Also, 13978(-15248) + 15457(13789) = 29
29 is the smallest postive linear
combination of 13978 and 15457.
Proof
• The proof consists of three steps.
1. Show how to choose an integer d > 0 that
could be the gcd of a and b.
2. Show that d is a common divisor, I.e. show
that d | a and d | b
3. Show that any other common divisor c of a
and b must also divide d.
1. Choose d
• Given non-zero integers a,b, let S be the
set of positive linear combinations of a,b.
S = {as+bt | s,t are integers and as+bt > 0}
• Clearly S is a set of non-empty positive
integers.
By the WOP, S has a least element, d.
2: Show d|a and d|b
• Divide a by d, recalling that d = as + bt.
•
•
•
a =dq + r = (as + bt)q + r, where 0 ≤ r < d.
Then r = a(1-sq)+b(-tq)
So r is a linear combination of a and b.
If r > 0, then r would have to be in S.
But this is impossible, since r < d.
So r must be 0, a = dq, and d|a.
Use symmetry (exchange the names of a and b)
to see that d|b as well as a.
So d is a common divisor, as required.
3. Show any other common
divisor must divide d
• Let c be any common divisor of a and b.
Say a = ch and b = ck.
• Then d = as + bt = chs + ckt = c(hs+kt)
• So c|d.
Corollary
• If a and b are relatively prime, then there
are integers s and t with as + bt = 1.
Euclidean Algorithm
gcd =
15457
+ 209
13978 1
X
– 189
||
1479
9 X+
667
2 X–
145
4 X+
87
1 X–
58
1 X+
29
2
0
||
+
20
||
+
9
||
+
2
||
+
1
||
+
1
+
0
15457(-189)+13978(209)=29
Download