How does the euclidean algorithm work?