Question: PLEASE USE MATLAB!! WRITE THE CODE EFFICIENTLY AND USE A WHILE LOOP 12. The greatest common divisor of two natural numbers a and b is
12. The greatest common divisor of two natural numbers a and b is denoted gcd(a,b). Euler's algorithm for computing gcd(a,b) uses the following ideas. Assuming a>b, divide a by b, and determine the quotient q and remainder r. Thus a=bq+r, where b>r since the remainder must be less than b. If r=0 then gcd(a,b)=b. If not, notice that gcd(b,r)=gcd(r,b)=gcd(abq,b)=gcd(a,b) where the last equality reflects the easily-confirmed fact that anything that divides both a and b also divides both abq and b, and vice-versa. Thus you can find gcd(a,b) by instead finding gcd(b,r) where a>b and b>r. In other words, to find gcd(a,b) one can simply replace a and b by b and r respectively and repeat the process. The successive remainders r must get smaller so you must eventually get r=0; then the corresponding b is the gad. Write an efficient program to implement Euler's algorithm. Use your program as part of another program to compute the ged of any set of n natural numbers, generalizing the observation that gcd(a,b,c)=gcd(gcd(a,b),c)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
