division and gcd
DESCRIPTION
Division and GCD. CSC2110 Tutorial 7 Darek Yung. Outline. Self Introduction Announcement Quick Review Example Q & A. Self Introduction. Yung Chun Kong, Darek Responsible for Topics in Number Theory Tutorial 7 – 9 The third class work Office: SHB 115 - PowerPoint PPT PresentationTRANSCRIPT
Division and GCD
CSC2110 Tutorial 7
Darek Yung
Outline
Self Introduction Announcement Quick Review Example Q & A
Self Introduction
Yung Chun Kong, Darek Responsible for
• Topics in Number Theory • Tutorial 7 – 9• The third class work
Office: SHB 115 Office hour: Wed – Fri, 3pm – 7pm Feel free to raise question in newsgroup
Announcement
You can collect your class work 1 from Tom (SHB 115)
Quick Review
Divisibility Division Theorem GCD (Extended) Euclid’s GCD Algorithm Linear Combination Die Hard
Divisibility
If a | b, then a | bc for all c. If a | b and b | c, then a | c. If a | b and a | c, then a | sb + tc for all s and
t. For all c ≠ 0, a | b if and only if ca | cb.
Division Theorem
a = qb + r, 0 r < b q, r are unique
GCD
Every common divisor of a and b divides GCD(a, b)
GCD(ka, kb) = k * gcd(a,b) for all natural number k
If GCD(a, b) = GCD(a, c) = 1, GCD(a, bc) = 1
If a | bc and GCD(a, b) = 1, a | c GCD(a, b) = GCD(b, rem(a, b))
(Extended) Euclid’s GCD Algorithm
By Division Theorem• a = qb + r
And GCD property• GCD(a, b) = GCD(b, rem(a, b))
We will have examples later
Linear Combination
sa + tb is a linear combination of a and b Smallest positive linear combination, SPC SPC(a, b) = GCD(a, b)
Die Hard
Goal: want to z gallon of water by using jugs with x and y gallon capacities
Solved by SPC = GCD, i.e. EE GCD Algorithm
Example
True / False
• Q1: False, e.g. when x is multiple of p• Q2: False, e.g. when y is multiple of x• Q3: True, definition of prime
Example
True / False
• Q4: False, e.g. when s = t = 1• Q5: False, e.g. when m = 2, a = 4, s=t=b=1• Q6: False, the smallest POSITIVE one
Example
True / False
• Q7: True, consider: ka + kb = k(a+b)• Q8: False, should be “divides”
e.g. GCD(12,18) = 6, 2 | 6
• Q9: True, implies GCD(a, b) = GCD(a, c) = 1• Q10: True, GCD(a, bc) >= GCD(a, c)
Example
True / False
• Q11: False, when z is multiple of GCD(x, y)• Q12: False, e.g. consider z = x // z = GCD(x, y)
Example
True / False
• Q13: False, e.g. when z is not multiple of x, y = xz
• Q14: False, e.g. when y is multiple of x, z is not• Q15: True,
always able to find x, s.t. GCD(x,y)=1 when y is given
Example
Find GCD(564, 978)• 978 = 1(564) + 414• 564 = 1(414) + 150• 414 = 2(150) + 114• 150 = 1(114) + 36• 114 = 3(36) + 6• 36 = 6(6) + 0GCD(564, 978) = 6Euclid’s GCD AlgorithmCaution: No mark will be given if steps are skipped!!!(Marks for steps will be given even if answer is wrong)
Example
Find SPC(364, 516) and values of s, t that
364s + 516t = SPC(364, 516)
Example
Find SPC(364, 516)• SPC(364, 516) = GCD(364, 516)• 516 = 1(364) + 152• 364 = 2(152) + 60• 152 = 2(60) + 32• 60 = 1(32) + 28• 32 = 1(28) +4• 28 = 7(4) + 0SPC(364, 516) = GCD(364, 516) = 4How to find s and t???
Example
• 516 = 1(364) + 152 152 = 516 – 1(364)
• 364 = 2(152) + 60 60 = 364 – 2(152) = -2(516) + 3(364)
• 152 = 2(60) + 32 32 = 152 – 2(60) = 5(516) – 7(364)
• 60 = 1(32) + 28 28 = 60 – 1(32) = -7(516) + 10(364)
• 32 = 1(28) +4 4 = 32 – 1(28) = 12(516) – 17(364)
• 28 = 7(4) + 0 s = -17, t = 12 Extended Euclid’s GCD Algorithm
Example
Find SPC(152, 376) and values of s, t that
152s + 376t = SPC(152, 376)
Example
• SPC(152, 376) = GCD(152, 376)• 376 = 2(152) + 72
72 = 376 – 2(152)
• 152 = 2(72) + 8 8 = 152 – 2(72) = -2(376) + 5(152)
• 72 = 9(8) + 0 SPC(152, 376) = 8, with s = 5, t = -2
Example
Find GCD(42, 56, 98)• GCD(42, 56, 98) = GCD(42, GCD(56, 98))• GCD(56, 98) = 14 (by Euclid’s GCD Algorithm)• GCD(40, 14) = 2 (by Euclid’s GCD Algorithm)
GCD(42, 56, 98) = 2
Example
Show how to get 81 gallons of water by using 366 and 297 gallon jugs.• 366 = 1(297) + 69
69 = 366 – 1(297)• 297 = 4(69) + 21
21 = 297 – 4(69) = -4(366) + 5(297)• 69 = 3(21) + 6
6 = 69 – 3(21) = 13(366) – 16(297)• 21 = 3(6) + 3
3 = 21 – 3(6) = -43(366) + 53(297)• 6 = 2(3) + 0 -43(366) + 53(297) = 3 -1161(366) + 1431(297) = 81
Example
How to save water (reduce number of rounds of transferring water)?• -297(366) + 366(297) = 0• -891(366) + 1098(297) = 0
-(1161-891)(366) + (1431-1098)(297) = 81
-270(366) + 333(297) = 81
Q & A