← LibraryModular Inverses and Chinese RemainderingEngineering · MathematicsLesson 57/385← PrevNext →
ArticlePublished 7 Aug 20263 min readBy Kevin Jogin

Engineering  /  Mathematics  — Integer Algorithms

Modular Inverses and Chinese Remaindering

Combining modular inversion with Chinese remaindering to move computations between a composite modulus and its coprime factors.

Page KV-MATH-0328Reading time 3 minReviewed 2026-08-07Author Kevin Jogin

Executive summary

Modular inversion and Chinese remaindering are the two directions of a single technique: decomposing a computation modulo a composite into independent computations modulo its coprime parts, and reassembling the result.

The reassembly requires an inverse for each part, which is where the two topics meet.

Learning objectives

  1. Combine inversion and remaindering into a working reconstruction procedure.
  2. Compare the direct and incremental reconstruction methods.
  3. Bound the total cost of a modular decomposition.

01The two directions

  1. Project

    Reduce a value modulo each of the coprime factors. Cheap: one division per factor.

  2. Compute

    Perform the whole computation independently in each Z_{nᵢ}, with smaller operands throughout.

  3. Reconstruct

    Reassemble the results into a single value modulo the product, using precomputed inverses.

The saving comes from step two. Multiplication is superlinear, so several small multiplications cost less than one large one. With k factors of equal size and quadratic multiplication, the work drops by roughly a factor of k.

02Incremental reconstruction

The direct formula computes all the inverses up front. An incremental variant merges the residues two at a time and is often preferable, because it needs only one inverse per merge and adapts naturally when factors are discovered progressively.

Algorithm

Incremental Chinese remaindering

Inputresidues aᵢ modulo pairwise coprime nᵢ
Outputx with x ≡ aᵢ (mod nᵢ) for all i
  1. Start with x = a₁ and M = n₁.
  2. For each subsequent pair (aᵢ, nᵢ):
  3.   Compute u = (aᵢ − x) mod nᵢ.
  4.   Compute v = M⁻¹ mod nᵢ by extended Euclid.
  5.   Set x = x + M · (u v mod nᵢ).
  6.   Set M = M · nᵢ.
  7. Return x mod M.
Cost  O(k · len(M)²) for k factors

03Cost accounting

Reconstruction cost breakdown
StepCostFrequency
Reduce input mod each nᵢO(len(M) · len(nᵢ))Once per factor
Inverse of M mod nᵢO(len(nᵢ)²)Once per merge; precomputable if factors are fixed
Multiply and accumulateO(len(M) · len(nᵢ))Once per merge
Final reductionO(len(M)²)Once

When the same factor set is reused — the usual case in modular algorithms, where a fixed list of primes is chosen in advance — every inverse is precomputed once and the per-reconstruction cost falls to multiplications and additions only.

04Frequently asked questions

Is the decomposition worthwhile for only two factors?

Yes, and RSA decryption is exactly that case. Two factors of half length each, with quadratic multiplication, gives roughly a fourfold speedup even after reconstruction overhead.

What if the factors are not coprime?

The reconstruction is not well defined. Consistency must be checked on the gcd of each pair, and the result is unique modulo the lcm rather than the product. Modular algorithms avoid the situation by choosing distinct primes.

How are the primes chosen in a modular algorithm?

Large enough that few are needed, small enough to fit a machine word so that arithmetic in each Z_p is single-precision. Primes just below 2^31 or 2^63 are the usual choice, with enough of them that their product exceeds a bound on the true result.

Sources and method

Structural reference: Victor Shoup, A Computational Introduction to Number Theory and Algebra, Version 1, Cambridge University Press, 2005 — book pages 62-63.

This page carries the durable method layer only: definitions, constructions, algorithms, complexity results and selection criteria, authored originally for KEVOS. No text is transcribed or paraphrased from the source, and no numeric tables or benchmark data are reproduced — these are routed to live authoritative sources instead.

Author: Kevin Jogin. Last reviewed 2026-08-07.

Continue learning

The Extended Euclidean AlgorithmArticle · MathematicsNEXT LESSON →Speeding Up Algorithms via Modular ComputationArticle · MathematicsEuclid's Algorithm for Integer GCDArticle · MathematicsRational ReconstructionArticle · Mathematics