The Euclidean algorithm can be used to find the greatest common divisor of two positive integers. At each step of the algorithm the smaller number is subtracted from the larger one. The algorithm terminates when the numbers are equal, which is then the greatest common divisor of the original numbers.
For two numbers and , let be the number of subtraction steps used by the Euclidean algorithm for computing the greatest common divisor of and .
For a number , let be the positive number coprime to that minimizes . If more than one number attains the minimum, the minimal is chosen.
For example, at least four steps are needed for computing the GCD of and any positive number coprime to . This number of steps is obtained by , yielding . You are also given and .