g = gcd(a, b).
The relationship between inputs and outputs is:
- If
sub_directionis true:g = s * a - t * b - If
sub_directionis false:g = t * b - s * a
(s, -t) or (-s, t) are the
Bezout coefficients (according to sub_direction).
g = gcd(a, b).
The relationship between inputs and outputs is:
sub_direction is true: g = s * a - t * bsub_direction is false: g = t * b - s * a(s, -t) or (-s, t) are the
Bezout coefficients (according to sub_direction).
pub fn egcd,
+Drop,
+Add,
+Mul,
+DivRem,
+core::num::traits::Zero,
+core::num::traits::One,
+TryInto>,
>(
a: NonZero, b: NonZero,
) -> (T, T, T, bool)
use core::math::egcd;
let (g, s, t, dir) = egcd::(12, 8);
assert!(g == 4);
Was this page helpful?