# Extended Euclidean algorithm

This calculator implements Extended Euclidean algorithm, which computes, besides the greatest common divisor of integers a and b, the coefficients of Bézout's identity

This content is licensed under Creative Commons Attribution/Share-Alike License 3.0 (Unported). That means you may freely redistribute or modify this content under the same license conditions and must attribute the original author by placing a hyperlink from your site to this work https://planetcalc.com/3298/. Also, please do not modify any references to the original work (if any) contained in this content.

This site already has The greatest common divisor of two integers, which uses Euclidean algorithm. As it turns out (for me), there exists Extended Euclidean algorithm. This algorithm computes, besides the greatest common divisor of integers a and b, the coefficients of Bézout's identity, that is integers x and y such that

So it allows to compute the quotients of a and b by their greatest common divisor.

You can see the calculator below, and theory, as usual, us under the calculator

Extended algorithm uses recursion, and computes coefficients on its backtrack. The formulas for calculations can be obtained from the following considerations:

Let us know coefficients for pair , such as:

,

and we need to calculate coefficients for pair , such as:

First, we replace with:

, where

- quotient from integer division of b to a,

and use it as substitute in:

Then, after regroup we get:

By comparing this with starting equation we can express x and y:

Start of recursion backtracking is the end of Euclidean algorithm, when a = 0 and GCD = b, so first x and y are 0 and 1 respectively. Further coefficients are computed using the formulas above.

## Comments