euclidean algorithm

http://en.wikipedia.org/wiki/Euclidean_algorithm