pub trait Gcd {
// Required method
fn gcd(self, other: Self) -> Self;
}
Expand description
最大公約数。
Complexity
$O(\log(\min\{m, n\}))$ time.
Examples
use nekolib::math::Gcd;
assert_eq!(12_u32.gcd(18), 6);
assert_eq!(13_i32.gcd(-3), 1);
assert_eq!(60_u32.gcd(90).gcd(150), 30);
assert_eq!(0_u32.gcd(0), 0);
assert_eq!(0_u32.gcd(1), 1);