Finds integers x and y with ax + by = the greatest common divisor. Running the Euclidean algorithm while also tracking how many of a and of b each remainder holds leaves x and y behind once the division comes out even. This is the basis for solving linear Diophantine equations.
For two whole numbers and , this finds whole numbers and satisfying the following.
That such and always exist is known as Bezout's identity. The ordinary Euclidean algorithm returns only the greatest common divisor, but tracking how many of and of each remainder holds leaves and behind once the division comes out even.
Take and . The greatest common divisor is 2, with and . Checking, .
A linear Diophantine equation has whole-number solutions only when is a multiple of the greatest common divisor. This calculation finds one such solution to start from.
It also finds with , the inverse modulo . When and share no factor, can be solved and that is the answer. Cryptography relies on this.
The pair , is not unique. Adding to and subtracting from keeps the identity true. The pair the algorithm returns is the one given here.