Problem

The method for solving ax + by = gcd(a, b) described in this chapter involves a considerab...

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)

(1) Set x = 1, g = a, v = 0, and w = b.

(2) If w = 0 then set y = (g ax)/b and return the values (g, x, y).

(3) Divide g by w with remainder, g = qw + t, with 0 t < w.

(4) Set s = x qv.

(5) Set (x, g) = (v,w).

(6) Set (v,w) = (s, t).

(7) Go to Step (2).

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 6