Division and GCD

# Division and GCD

Télécharger la présentation

## Division and GCD

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Division and GCD CSC2110 Tutorial 7 Darek Yung

2. Outline • Self Introduction • Announcement • Quick Review • Example • Q & A

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

4. Announcement • You can collect your class work 1 from Tom (SHB 115)

5. Quick Review • Divisibility • Division Theorem • GCD • (Extended) Euclid’s GCD Algorithm • Linear Combination • Die Hard

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

7. Division Theorem • a = qb + r, 0  r < b • q, r are unique

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

9. (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

10. Linear Combination • sa + tb is a linear combination of a and b • Smallest positive linear combination, SPC • SPC(a, b) = GCD(a, b)

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

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

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

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

15. Example • True / False • Q11: False, when z is multiple of GCD(x, y) • Q12: False, e.g. consider z = x // z = GCD(x, y)

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

17. 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) + 0 • GCD(564, 978) = 6 • Euclid’s GCD Algorithm Caution: No mark will be given if steps are skipped!!! (Marks for steps will be given even if answer is wrong)

18. Example • Find SPC(364, 516) and values of s, t that 364s + 516t = SPC(364, 516)

19. 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) + 0 • SPC(364, 516) = GCD(364, 516) = 4 How to find s and t???

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

21. Example • Find SPC(152, 376) and values of s, t that 152s + 376t = SPC(152, 376)

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

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

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

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

26. Q & A