b. Prove the following fact:
( integers a, b, q, r)[ a = qb + r) → gcd(a, b) = gcd(b, r)] (1)
Hint #1: Assume that a = qb + r and that e divides both a and b so that a = q₁c and b
= q2c. Then prove that c also divides r. This says that anything that divides a and b also
divides b and r.
Hint #2: Assume that a = qb + r and that d divides both b and r so that b = q3d and r
= q4d. Then prove that d also divides a. This says that anything that divides b and r also
divides a and b.
Therefore if a = qb + r, then (a, b) and (b, r) have identical divisors, so they must have
the same greatest common divisor.
c. Here is the pseudocode for the Euclidean algorithm.
GCD (positive integer a; positive integer b)
//a
>Б
Local variables:
integers i, j
i=a
j=b
while j≠ 0 do
compute i=qj+r,0<r<j
i=j
j=r
end while
// i now has the value gcd(a, b)
return i;
end function GCD
Prove that Q: gcd(i,j) = gcd(a,b) is a loop invariant in the Euclidean algorithm. Show
the details of each of the 3 steps. Hint: Use the Eq (1) result from part (b).