Idea. Recursive calculation of greatest common divisors [01DX]
Although it is not easy to calculate the set of all common divisors of two positive integers m,n, it will turn out to be easy to calculate the greatest common divisor \gcd {\mathopen {}\left (m,n\right )\mathclose {}}, and our characterisation of common divisors gives us an idea why:
- If n\mid m, then we know that \mathsf {CD}{\mathopen {}\left (m,n\right )\mathclose {}} = \mathsf {D}{\mathopen {}\left (n\right )\mathclose {}} and hence \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = n.
- Otherwise, we know that \mathsf {CD}{\mathopen {}\left (m,n\right )\mathclose {}} = \mathsf {CD}{\mathopen {}\left (n,\operatorname {rem}{\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}}, so \gcd {\mathopen {}\left (m,n\right )\mathclose {}} = \gcd {\mathopen {}\left (n,\operatorname {rem}{\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}}.
In summary, we have:
\gcd {\mathopen {}\left (m,n\right )\mathclose {}} = \begin {cases} n &\text {if } n\mid m \\ \gcd {\mathopen {}\left (n,\operatorname {rem}{\mathopen {}\left (m,n\right )\mathclose {}}\right )\mathclose {}} & \text {otherwise} \end {cases}The above is circular and so it isn’t automatically a valid definition; but it is suggestive of an algorithm…