In mathematics, the GCD of two integers is the largest positive integer that divides each of the integers.
For two integers, x and y, the greatest common divisor of x and y is denoted by gcd(x, y).
For example, the GCD of 8 and 12 is 4, that is, gcd(8,12)=4.
Several GCD algorithms are available.
The one on the right uses recursion and is concise.
function gcd( int a, int b )
if ( b == 0 )
return a
else
return gcd( b, a mod b )
end if
end function