Euclid's algorithm implementation.