Implement the greatest common divisor function