Skip to main content

Module chinese_remainder_theorem

Module chinese_remainder_theorem 

Source
Expand description

The Chinese remainder theorem.

See the book entry Divisibility and modular arithmetic.

Functions§

chinese_remainder
Solves the simultaneous congruences x ≡ r_i (mod m_i) and returns (x, M) with 0 ≤ x < M, where M = lcm(m_i), so that the solution set is x + kM. The moduli need not be pairwise coprime (Garner-style pairwise merging with gcd); returns an error when the congruences are inconsistent or M overflows i128.