Euclid’s algorithm finds the greatest common divisor of two positive integers and .

Here is the algorithm as Knuth notated it.

E1. [Find remainder.] Divide by and let be the remainder. (We will have ). E2. [Is it zero?] If , the algorithm terminates; is the answer. E3. [Reduce.] Set , , and go back to step E1.