Professional Documents
Culture Documents
B) Using The Extended Euclidean Algorithm Find All Pairs of Integers X and y That Satisfy The Equation 427x + 154y GCD (427, 154)
B) Using The Extended Euclidean Algorithm Find All Pairs of Integers X and y That Satisfy The Equation 427x + 154y GCD (427, 154)
b) Using the Extended Euclidean Algorithm find all pairs of integers x and y that satisfy
the equation 427x + 154y = gcd(427, 154).
We know that 14 = 119 - 3(35) from (3), so now substitute for 14 into (6):
35 - 2(119 - 3(35)) = 7
35 - 2(119) + 6(35) = 7
7(35) - 2(119) = 7 (7)
We know that 35 = 154 - 119 from (2), so now substitute for 35 into (7):
7(154-119) - 2(119) = 7
7(154) - 7(119) - 2(119) = 7
7(154) - 9(119) = 7 (8)
We know that 119 = 427 - 2(154) from (1), so now substitute for 119 into (8):
Thus, a solution is x= -9 and y=25. To find all solutions, consider the following
equation:
427a + 154b = 0
61a + 22b = 0
61a = -22b. Since gcd(a,b)=1, the smallest solution is a=22, b=-61. It follows that the
complete solution for x and y is
x = -9+22n,
y=25-61n, for all nZ.
2) Write a recursive C function that computes the gcd of two given non-negative integers
a and b. (Note: You are guaranteed that both a and b aren't 0, since gcd(0,0) isn't defined.
Also, remember that you can NOT divide by 0!!!) The prototype is given to you below:
if (a == 0) return b;
if (b == 0) return a;
if (a%b == 0)
return b;
else
return gcd(a%b, b);