The method for solving ax + by = gcd(a, b) described in this chapter involves a considerable amount of manipulation and back substitution. This exercise describes an alternative way to compute x and y that is especially easy to implement on a computer.
(a) Show that the algorithm described in Figure computes the greatest common divisor g of the positive integers a and b, together with a solution (x, y) in integers to the equation ax + by = gcd(a, b).
(b) Implement the algorithm on a computer using the computer language of your choice.
(c) Use your program to compute g = gcd(a, b) and integer solutions to ax+by = g for the following pairs (a, b).
(i) (19789, 23548)
(ii) (31875, 8387)
(iii) (22241739, 19848039)
(d) What happens to your program if b = 0? Fix the program so that it deals with this case correctly.
(e) For later applications it is useful to have a solution with x > 0. Modify your program so that it always returns a solution with x > 0. [Hint. If (x, y) is a solution, then so is (x + b, y - a).]
Figure 1: Efficient algorithm to solve ax + by = gcd(a, b)
|
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.