function NaiveGCD(a, b)
Input: a, b (two positive integers)
Output: gcd(a, b) (the greatest common divisor of a and b)
while a ≠ b do
if a > b then
a ( a – b
else
b ( b – a
endif
endwhile
return(a)
end NaïveGCD
function EuclidGCD(a, b)
Input: a, b (two nonnegative integers)
Output: gcd(a, b) (the greatest common divisor of a and b)
while b ≠ 0 do
Remainder ( a mod b
a ( b
b ( Remainder
endwhile
|
~
¤
¦
А
В
2
X
ђ
¬
Ш
т
urn(a)
end EuclidGCD
function BabylonianSQRT(a, error)
Input: a (a positive number), error (a positive real number)
accurate to within error
x ( a
while |x - a/x| > error do
x ( (x + a/x)/2
endwhile
return(x)
end BabylonianSQRT
