Algorithm Implementation/Mathematics/Extended Euclidean algorithm

Python
Both functions take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b).

Modular inverse
An application of extended GCD algorithm to finding modular inverses: