Euclidean algorithm (source code)

= Euclidean algorithm
{wiki}

The Euclidean algorithm repeatedly replaces $(a,b)$ by $(b,a\bmod b)$ and terminates at $\gcd(a,b)$.