Function aoc::util::gcd

source ·
pub fn gcd<T>(a: T, b: T) -> T
where T: PartialEq + Rem<Output = T> + From<u8> + Copy,
Expand description

Compute the greatest common divisor.

The greatest common divisor is defined as largest positive integer (among a set of integers that are not all zero) that divides each of the integers.

Computes the greatest common divisor using the Euclidean algorithm.

§Example

assert_eq!(util::gcd(48, 18), 6);
assert_eq!(util::gcd(18, 48), 6);