Euclidean Algorithm.This is the classic algorithm for using Euclid's method for finding the greatest common divisor. The algorithm will return the greatest common divisor and an array of the quotients.LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JlEocmVzdGFydEYnLyUlYm9sZEdRJmZhbHNlRicvJSdpdGFsaWNHRjEvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLUkjbW9HRiQ2LlEiO0YnRi9GNC8lJmZlbmNlR0YxLyUqc2VwYXJhdG9yR1EldHJ1ZUYnLyUpc3RyZXRjaHlHRjEvJSpzeW1tZXRyaWNHRjEvJShsYXJnZW9wR0YxLyUubW92YWJsZWxpbWl0c0dGMS8lJ2FjY2VudEdGMS8lJ2xzcGFjZUdRJjAuMGVtRicvJSdyc3BhY2VHUSwwLjI3Nzc3NzhlbUYneuclidgcd:=proc(a,b)
description"This process will derive the gcd(a,b) of given parameters.";
#option trace;
local i,r: global R, Q;
with(StringTools);
#Check for greatest parameter and initialize R(remainder table)and Q(Quotient table);
if a>b then
R[0]:=b:
Q[1]:=trunc(a/b):
R[1]:=b*frac(a/b):
cat(a ,"=", Q[1] ,"*", b ,"+", R[1]);
print(%);
else
R[0]:=a;
Q[1]:=trunc(b/a):
R[1]:=a*frac(b/a):
cat(b ,"=", Q[1] ,"*", a ,"+", R[1]);
print(%);
end if;
#Now loop to find quotients and remainders
for i from 2 while r<>0 do
Q[i]:=trunc(R[i-2]/R[i-1]):
R[i]:=R[i-1]*frac(R[i-2]/R[i-1]):
cat(R[i-2] ,"=", Q[i] ,"*", R[i-1] ,"+", R[i]);
print(%);
r:=R[i]:
end do;
print();
#Convert the quotients to an Array to be used by other programs.
Q:=convert(Q,array);
#Output section
print(Quotients = Q());
cat("gcd(",a,",",b,")=",R[i-2]);
print(%);
end proc:ExampleFind the greatest common divisor of 480 and 1180.euclidgcd(241,500);Q();