Divisibility The Euclidean algorithmourgcd := proc(a,b)
local atemp, btemp;
(atemp, btemp) := (a, b);
while btemp > 0 do
(atemp, btemp) := (btemp,modp(atemp,btemp));
end do;
atemp;
end proc:
ourgcd(81959,73963);
ourgcdcount := proc(a,b)
local atemp, btemp, c;
(atemp, btemp) := (a, b); c := 0;
while btemp > 0 do
(atemp, btemp) := (btemp, modp(atemp,btemp));
c := c+1;
end do;
[atemp, c];
end proc:ourgcdcount(81959,73963);ourgcdcount(12413141414234242423413412,123123123909023233211);ourgcdcount(987,610);Linear Combinationsourextendedgcd := proc(a,b)
local atemp, btemp, x, xx, y, yy, r, q;
(atemp, btemp) := (a, b);
(xx, x) := (1, 0); (yy, y) := (0, 1);
while btemp > 0 do
r := modp(atemp,btemp); q := (atemp-r)/btemp;
(atemp, btemp) := (btemp, r);
(xx, x) := (x, xx - x*q);
(yy, y) := (y, yy - y*q);
end do;
[atemp, (xx,yy)];
end proc:
ourextendedgcd(817,615);