compute the greatest common divisor using Euclidean algorithm