pub fn crt<T: Copy + Integer>(divisor_remainder_pairs: &[(T, T)]) -> T {
	// First, compute the product of all of the divisors.
	let product = divisor_remainder_pairs
		.iter()
		.fold(T::one(), |acc, (div, _rem)| acc * *div);

	let total = divisor_remainder_pairs
		.iter()
		.fold(T::zero(), |acc, (div, rem)| {
			let partial_product = product / *div;
			acc + *rem * partial_product * modular_multiplicative_inverse(partial_product, *div).unwrap()
		});

	total % product
}
/// Compute the unique solution to a system of congruences using the Chinese Remainder Theorem.
///
/// If the `.1` subscripts of the given slice are pairwise coprime, and the `.0` subscripts of the
/// given slice are integers between 0 and their corresponding .1 subscript, then the Chinese
/// Remainder Theorem asserts that there is one and only one integer `x` between 0 and the product
/// of all of the `.1` subscripts for which the remainder of the Euclidean division of `x` and each
/// of the `.1` subscripts is the same as the value in the corresponding `.0` subscript.
///
/// See also the article on [Wikipedia](https://en.wikipedia.org/wiki/Chinese_remainder_theorem).
Compute the unique solution to a system of congruences using the Chinese Remainder Theorem.

See also the article on [Wikipedia].
Compute the unique solution to a system of congruences using the Chinese Remainder Theorem . See also the article on [ Wikipedia ] .
pub fn crt<T: Copy + Integer>(divisor_remainder_pairs: &[(T, T)]) -> T {
	// First, compute the product of all of the divisors.
	let product = divisor_remainder_pairs
		.iter()
		.fold(T::one(), |acc, (div, _rem)| acc * *div);
	let total = divisor_remainder_pairs
		.iter()
		.fold(T::zero(), |acc, (div, rem)| {
			let partial_product = product / *div;
			acc + *rem * partial_product * modular_multiplicative_inverse(partial_product, *div).unwrap()
		});
	total % product
}
pub fn crt < T : Copy + Integer > ( divisor_remainder_pairs : & [ ( T , T ) ] ) -> T { // First, compute the product of all of the divisors. let product = divisor_remainder_pairs . iter ( ) . fold ( T :: one ( ) , | acc , ( div , _rem ) | acc * * div ) ; let total = divisor_remainder_pairs . iter ( ) . fold ( T :: zero ( ) , | acc , ( div , rem ) | { let partial_product = product / * div ; acc + * rem * partial_product * modular_multiplicative_inverse ( partial_product , * div ) . unwrap ( ) } ) ; total % product }
Compute the unique solution to a system of congruences using the Chinese Remainder Theorem.
Compute the unique solution to a system of congruences using the Chinese Remainder Theorem .
divisor_remainder_pairs
&[(T, T)]
divisor_remainder_pairs
&[(T, T)]