Function utils::number::chinese_remainder

source ·
pub fn chinese_remainder<T: SignedInteger>(
    residues: impl IntoIterator<Item = T>,
    moduli: impl IntoIterator<Item = T, IntoIter: Clone>,
) -> Option<T>
Expand description

Solves a system of simultaneous congruences using the Chinese Remainder Theorem.

This function finds the smallest non-negative integer x where x % modulus = residue for each provided (residue, modulus) pair.

§Examples

assert_eq!(chinese_remainder([1, 2, 3], [5, 7, 11]), Some(366));
assert_eq!(366 % 5, 1);
assert_eq!(366 % 7, 2);
assert_eq!(366 % 11, 3);