(defn chinese-remainder
"[Chinese Remainder Algorithm](https://en.wikipedia.org/wiki/Chinese_remainder_theorem).
Accepts a sequence of [[ModInt]] instances (where the `modulus` of
all [[ModInt]] instances are relatively prime), and returns a [[ModInt]] `x`
such that `(residue input) == (mod x (modulus input))`.
For example:
```clojure
(let [a1 (m/make 2 5)
a2 (m/make 3 13)]
[(= 42 (chinese-remainder a1 a2))
(= (residue a1) (mod cr (modulus a1)))
(= (residue a2) (mod cr (modulus a2)))])
;;=> [true true true]
```"
[& modints]
(let [prod (transduce (map modulus) g/* modints)
xform (map (fn [mi]
(let [i (residue mi)
m (modulus mi)
c (g/quotient prod m)]
(g/* i c (residue (invert c m))))))]
(-> (transduce xform g/+ modints)
(g/modulo prod))))