The Extended Euclidean Algorithm (2/10)

The Extended Euclidean Algorithm (2/10)
• Question: Can we write the GCD of two numbers a and b
•
•
•
•
•
as a linear combination of a and b, i.e., can we find
integers x and y such that a x + b y = GCD(a, b) ?
Answer: Yes.
Is there an efficient algorithm to find one such equation?
Answer: Yes, the Extended Euclidean Algorithm(EEA).
Is this equation unique?
Answer: No, there are infinitely many such equations, but
if d = GCD(a, b) and if a x1 + b y1 = d is one such
equation, then all the equations will be of the form
a (x1 + k b /d) + b (y1 – k a /d) = d where k is any integer.
An Example of Using EEA
• Problem: Write GCD(234, 105) as a linear combination of
•
•
•
•
•
•
a = 234 and b = 105.
Solution produced by the EEA:
a = 2b + 24, so 24 = a – 2b
b = 4(24) + 9, so 9 = b – 4(24) = b – 4(a – 2b) = 9b – 4a
24 = 2(9) + 6, so 6 = 24 – 2(9)
= (a – 2b) – 2(9b – 4a) = 9a – 20b
9 = 1(6) + 3, so 3 = 9 – 6
= (9b – 4a) – (9a – 20b) = 29b – 13a
Check that it’s right! In fact, you can check your
correctness at every step.
Other Equations for This Pair?
• What other equations are there for 234 and 105?
• They will be of the form
(29 + (234/3)k) (105) + (-13 – (105/3)k (234) = 3
for any integer k.
• If k = -1, for example, we get
(29 – 78)(105) + (-13 + 35)(234) = -49(105) + 22(234) = 3
• Check it!
• For Wednesday, read Chapter 6 and do
Exercises 6.1 and 6.2 .