Question: Problem 1 - Implement the Euclidean Algorithm As discussed in class, the Euclidean algorithm finds the greatest common divisor of two integers a and b.

Problem 1 - Implement the Euclidean Algorithm As discussed in class, the Euclidean algorithm finds the greatest common divisor of two integers a and b. As a refresher, the algorithm runs roughly as follows 1. Setg := greater of a and b; l := the lesser. 2. Find the unique q, r for which g=lq + r by the division algorithm. 1. If r = 0, then the GCD is l, and should be returned 2. Otherwise, set g:=l and l :=r; repeat from step 2. In [7]: def gcd(a,b): g = max(a,b) 1 = min(a,b) q = g // 1 #8 // 1 = greatest integer less than g/l r = g % 1 # g % 1 = least positive integer congruent to g (mod 1) (least positive reside) while True: # Change while True: to a proper loop-condition pass # Replace 'pass' with your code return 1 # Replace '1' with a return value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
