Motivation
The Euclidean algorithm finds the greatest common divisor (gcd) of two integers by repeated division with remainder. The extended Euclidean algorithm does more: alongside the gcd it returns two integer coefficients and that express the gcd as a linear combination of the two inputs. These coefficients are exactly what you need to compute a multiplicative inverse in — the basis of RSA, of solving linear congruences, and of the Chinese remainder theorem.
Formal definition
For , Bézout's lemma guarantees integers with
The extended Euclidean algorithm constructs such a pair explicitly. It performs the Euclidean division
iteratively, replacing by at each step. In parallel it carries the coefficients through the recurrence
starting from and . When the remainder reaches , the previous value is the gcd, and its satisfy the Bézout identity.
Modular inverse in
If , then immediately gives
so (reduced into ) is the inverse in . In the calculator, find it by setting and the modulus .
Worked example
Take the standard example , — the calculator's default above. The divisions with remainder are:
The last non-zero remainder is . Back-substituting yields the Bézout representation
so and . These are exactly the values shown in the calculator's step table.
Common pitfalls
- Forgetting signs: or is often negative. Over that is correct; only for an inverse in do you reduce into .
- Wrong remainder range: Euclidean division requires . A negative remainder produces a wrong sequence of steps.
- Inverse without coprimality: exists in only when . Otherwise the congruence has no solution.
- Swapping and : the gcd is unchanged, but and swap roles — keep track of which coefficient belongs to which number.