compute the greatest common divisor using euclid's algorithm