Function utils::number::egcd

source ·
pub fn egcd<T: SignedInteger>(a: T, b: T) -> (T, T, T)
Expand description

Computes the greatest common divisor (GCD) using the extended Euclidean algorithm.

Returns a tuple (gcd, x, y) where x, y are the coefficients of Bézout’s identity:

ax + by = gcd(a, b)

§Examples

assert_eq!(egcd(252, 105), (21, -2, 5));
assert_eq!((252 * -2) + (105 * 5), 21);