Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 4

Solving Systems of Linear Congruences with the Chinese Remainder Theorem

Recommended resources

Hello. In our last lesson, we developed a complete formula for Euler's totient function, . A key part of that derivation was the multiplicative property: for coprime and . In the conclusion, I mentioned that the Chinese Remainder Theorem (CRT) offers a deeper, more structural reason for this property. We will now explore this powerful theorem in its own right.

This lesson focuses on solving systems of linear congruences. Imagine being asked to find a number that leaves a remainder of 2 when divided by 3, a remainder of 3 when divided by 5, and a remainder of 2 when divided by 7. The CRT provides a systematic method for finding such a number. This tool is not just a number-theoretic puzzle; it has significant applications in cryptography, particularly for optimizing RSA computations and analyzing certain attacks, which we will see later in the course.

Our goal is to understand the theorem's statement, learn a constructive method to find solutions, and apply it to concrete problems.

The Statement of the Theorem

A system of simultaneous linear congruences is a set of equations of the form:

We are looking for an integer that satisfies all of these conditions simultaneously. The Chinese Remainder Theorem tells us precisely when a solution exists and what it looks like.

Chinese remainder theorem

This resource formally states the theorem and discusses the crucial conditions for existence and uniqueness of a solution.

Please read the first two sections. Start with the statement for integers. This will give you the formal wording of the theorem, including the condition that the moduli n_i must be pairwise coprime. Then, read the section on uniqueness and existence conditions. This part elaborates on why the coprime condition is essential and what happens if it is not met.

As you've read, the CRT guarantees a unique solution modulo provided that the moduli are pairwise coprime (i.e., for all ).

The beauty of the standard proof of the CRT is that it is constructive. It doesn't just prove that a solution exists; it provides an explicit algorithm for finding it.


A Constructive Proof and Algorithm

The following video provides an excellent, step-by-step constructive proof of the Chinese Remainder Theorem. Given your preference for rigorous, proof-based learning, you will find this derivation satisfying. It directly translates into a practical algorithm.

Chinese Remainder Theorem -- Number Theory 11

This video walks through a constructive proof for the existence of a solution, followed by a proof of its uniqueness.

First, watch the constructive proof. Pay close attention to how the solution x is built. The presenter defines helper values (which he calls capital N_i) and uses modular inverses (which he calls x_i) to assemble the final result. Next, watch the proof of uniqueness. This part demonstrates why any two solutions to the system must be congruent modulo the product of all moduli.

Let's summarize the algorithm derived from the constructive proof. To solve the system of congruences:

  1. Check the condition: Verify that all moduli are pairwise coprime.
  2. Compute the product modulus: Calculate .
  3. Compute partial moduli: For each , calculate . This is the product of all moduli except .
  4. Find modular inverses: For each , find the modular inverse of modulo . That is, find such that . As we've seen, this is possible because , and we can use the Extended Euclidean Algorithm to find .
  5. Construct the solution: The solution is given by the formula:

Notice why this works. When we look at the sum modulo some , every term where becomes zero because contains as a factor. The only term that survives is the -th term, . Since , this term simplifies to , satisfying the -th congruence. This holds for all , so the constructed is a solution to the entire system.


A Worked Example

Let's now apply this algorithm to a concrete problem. The next segment of the video you just watched solves a system of three congruences using exactly the method we outlined.

Chinese Remainder Theorem -- Number Theory 11

This part of the video provides a clear, step-by-step solution to a system of three congruences.

Please watch the first example. Follow along as the presenter calculates N, the N_i (our M_i), the x_i (our y_i), and assembles the final answer.

Let's re-trace the steps from the video for the system:

  1. Condition: The moduli are . They are pairwise coprime.

  2. Product Modulus: .

  3. Partial Moduli:

  4. Modular Inverses:

    • For : We need . Since , we need . So, . (Note: the video calculates , but my re-check shows , not 2 as in the video. The principle is the same. Let's follow the video's calculation for consistency with the resource: , so . Thus . The video example has , so the video states and . Let's use the video's calculation for consistency. The video says , so . Okay. The video for the first example has a small error in narration/calculation for . Let's use the correct one. , so its inverse is . .
    • For : We need . . We need . The inverse of 2 mod 7 is 4, since . So, .
    • For : We need . . We need . So, .
  5. Construct Solution:

    Finally, we take the result modulo :

    The unique solution is 59. You can quickly check: , , and . It works.


An Alternative: The Iterative Method

The summation formula is elegant and demonstrates the structure of the solution well. For practical computation, especially if you were to implement this, an iterative approach can be just as effective. The idea is to solve the system two congruences at a time.

  1. Solve the first two congruences: and . This yields a single solution .
  2. Take this new congruence and combine it with the third one: and .
  3. Repeat this process until all congruences have been incorporated.

The following resource demonstrates this technique on a three-congruence system.

[PDF] MATH 433 Applied Algebra Lecture 9: Chinese Remainder Theorem.

This document provides a concise example of the iterative method for solving a system of congruences.

On page 2, find the problem that begins with "Solve simultaneous congruences" and presents a system of three equations. Read the step-by-step solution. Notice how it first combines the congruences modulo 3 and 4 into a single congruence modulo 12, and then combines that result with the congruence modulo 5.


Conclusion

In this lesson, we have explored the Chinese Remainder Theorem, a fundamental result in number theory with significant cryptographic applications. We've established the conditions under which a system of linear congruences has a solution and seen that this solution is unique modulo the product of the moduli. Most importantly, we have learned and practiced a constructive algorithm to find this solution.

Key Takeaways:

  • The Chinese Remainder Theorem solves systems of linear congruences .
  • A solution is guaranteed to exist if the moduli are pairwise coprime.
  • The solution is unique modulo .
  • The constructive formula for the solution is , where and .
  • The theorem has an intimate connection to the structure of the ring , explaining why functions like Euler's totient are multiplicative.

In our next lesson, we will shift our focus from solving equations to analyzing the efficiency of algorithms that are critical for cryptography. We will begin by analyzing the square-and-multiply method for modular exponentiation, a technique that makes computations like those in RSA feasible.