The Chinese remainder theorem states that a system of congruences , always has a solution if the moduli are relatively prime in pairs; the solution is unique (mod ), where is the product of the moduli.
This theorem is employed to increase efficiency in calculating with large numbers by making use of smaller numbers in most of the calculation. For example, suppose a lengthy calculation involves many 10-digit integers. Most of the calculation can be done with five-digit integers as follows. Choose four relatively prime moduli , and of five digits each, for example , , , and . Their product has 20 digits, twice the number of digits in the data. By the Chinese remainder theorem each integer in the data can be uniquely represented by its residues (mod ), (mod ), (mod ), and (mod ), respectively. Because each residue has no more than five digits, the arithmetic can be performed efficiently on these residues with respect to each of the moduli, yielding answers , , , and , where each has no more than five digits. These numbers, in turn, are combined by the Chinese remainder theorem to obtain the final result , which is correct to 20 digits.
Even though the lengthy calculation is repeated four times, once for each modulus, most of it only uses five-digit integers and is accomplished quickly without overwhelming the machine’s memory. Details of a machine program describing the method together with typical numerical results can be found in Newman (1967). See also Apostol and Niven (1994, pp. 18–19).