Sub topic 2
Congruence notation: what a ≡ b (mod n) means
This chapter assumes you can do integer division with a quotient and remainder, and that you know what a factor is. It also assumes you can read a statement like "n divides m." The previous chapter showed that every integer a can be written as a = n·q + r with 0 ≤ r < n. This chapter turns that fact into a compact notation. The rest of the tutorial relies on it.
The definition
Let n be a positive integer, called the modulus. Two integers a and b are congruent modulo n when n divides their difference:
a ≡ b (mod n) means n | (a − b)
Read it as "a is congruent to b modulo n." The symbol ≡ is not equality. It says that a and b are the same as far as division by n is concerned.
Check with numbers: 47 ≡ 5 (mod 6), because 47 − 5 = 42 and 6 divides 42. Also 47 ≡ 11 (mod 6), because 47 − 11 = 36.
Three equivalent ways to say it
The same statement has three common forms. You will switch between them constantly in CAT problems.
| Form | Statement for 47 and 5, modulus 6 |
|---|---|
| Divisibility of the difference | 6 divides 47 − 5 = 42 |
| Same remainder | 47 and 5 both leave remainder 5 on division by 6 |
| Shifted by a multiple | 47 = 5 + 6·7, so 47 differs from 5 by a multiple of 6 |
Here is why the forms agree. Write a = n·q₁ + r₁ and b = n·q₂ + r₂ with remainders between 0 and n − 1. Then a − b = n(q₁ − q₂) + (r₁ − r₂). The first part is already a multiple of n. So n divides a − b exactly when n divides r₁ − r₂. That difference lies strictly between −n and n, so it is a multiple of n only if it equals 0. Hence the remainders match.
Checking congruence in code
The definition translates directly into a test. Python's % operator returns a non-negative result for a positive modulus, so it matches the "same remainder" reading even for negative numbers.
def congruent(a, b, n):
return (a - b) % n == 0
print(congruent(47, 5, 6)) # True
print(congruent(-7, 3, 5)) # True
print(congruent(20, 3, 6)) # False
print(47 % 6 == 5 % 6) # TrueThe second line shows that −7 ≡ 3 (mod 5). The difference is −10, which is a multiple of 5. Both numbers leave remainder 3 when divided by 5, using the convention that the remainder is never negative.
Residue classes: infinitely many numbers, n remainders
For a fixed modulus n, the integers split into n groups. Each group holds all numbers with the same remainder. Such a group is a residue class. Congruent numbers always sit in the same class.
For modulus 6, the class of remainder 5 contains these values:
print([x for x in range(-20, 20) if x % 6 == 5])
# [-19, -13, -7, -1, 5, 11, 17]Consecutive members differ by exactly 6. Any member can stand in for the others. The standard choice is the least non-negative residue, the member from 0 to n − 1. That choice is the remainder from the division algorithm.
This is the main reason the notation helps. A huge number can be replaced by any smaller number in its class without changing anything that depends only on the remainder. Later chapters use this to shrink sums, products and powers.
Writing the remainder with ≡
The statement "N leaves remainder r when divided by n" is written N ≡ r (mod n). It carries extra information when r is not in the range 0 to n − 1. Compare these:
- 100 ≡ 4 (mod 6), since 100 = 6·16 + 4. Here 4 is the actual remainder.
- 100 ≡ −2 (mod 6), since 100 − (−2) = 102 = 6·17. This is a true congruence, but −2 is not the remainder.
To get the remainder from a congruence, convert the representative to the range 0 to n − 1 by adding n: −2 + 6 = 4. The chapter on negative remainders uses this shift as a shortcut.
Properties you can rely on
Congruence behaves like equality in several respects. For any integers a, b, c and modulus n:
- Reflexive: a ≡ a (mod n), because n divides 0.
- Symmetric: if a ≡ b then b ≡ a, because n | (a − b) gives n | (b − a).
- Transitive: if a ≡ b and b ≡ c, then a ≡ c. This holds because a − c = (a − b) + (b − c), a sum of two multiples of n.
These three properties are why residue classes are well defined. They also let you chain steps: 47 ≡ 11 (mod 6) and 11 ≡ 5 (mod 6), so 47 ≡ 5 (mod 6).
The next chapter shows how congruences can be added, subtracted and multiplied. Here we only need the fact that adding a multiple of n to a number never changes its class.
Edge cases and common errors
Modulus 1. Every integer is a multiple of 1, so a ≡ b (mod 1) is always true. There is only one residue class. The case is trivial but explains why remainders on division by 1 are always 0.
Negative or zero modulus. The modulus is taken as a positive integer. Division by 0 has no meaning. Divisibility by −n is the same as divisibility by n, so no new information appears.
Changing the modulus. If a ≡ b (mod n) and d is a factor of n, then a ≡ b (mod d). For example, 47 ≡ 5 (mod 6) implies 47 ≡ 5 (mod 3), and indeed both leave remainder 2. The reverse is false: 47 ≡ 5 (mod 3) does not give a congruence mod 6 unless the difference is also even. Here it is, but check each time. As a counter-example, 8 ≡ 2 (mod 3) but 8 ≢ 2 (mod 12).
Cancelling a common factor. You cannot always divide both sides of a congruence by the same number. 6 ≡ 10 (mod 4), since both leave remainder 2. Dividing both sides by 2 gives 3 ≡ 5 (mod 4), which is false, because the difference is 2. Division needs extra care and is covered later.
Mixing up the number and its remainder. The statement 47 ≡ 5 (mod 6) does not mean that 47 equals 5. If a CAT question asks for the quotient, or for the number itself, a congruence alone is not enough. It fixes the number only up to a multiple of n.
Using the notation on a CAT-style question
Question: a number N leaves remainder 3 when divided by 7. What remainder does N + 20 leave when divided by 7?
Write N ≡ 3 (mod 7). Since 20 = 7·2 + 6, we have 20 ≡ 6 (mod 7). Adding the two congruences, which the next chapter justifies, gives N + 20 ≡ 3 + 6 = 9 ≡ 2 (mod 7). The remainder is 2.
Check with a concrete case. Take N = 10, which leaves remainder 3 on division by 7. Then N + 20 = 30 and 30 = 7·4 + 2. The remainder is 2, as predicted.
Exercise
Decide whether 125 ≡ 17 (mod 9) is true. Show the difference test and the same-remainder test.
Show answer
Difference test: 125 − 17 = 108 = 9 × 12, so 9 divides the difference and the congruence is true. Same-remainder test: 125 = 9·13 + 8 and 17 = 9·1 + 8, so both leave remainder 8.
Exercise
A number N satisfies N ≡ −4 (mod 9). What is the remainder when N is divided by 9? Name two other positive numbers that N could equal.
Show answer
Add the modulus to move into the range 0 to 8: −4 + 9 = 5, so the remainder is 5. Any number of the form 5 + 9k works, for example 5 and 14 (also 23, 32, and so on).
Exercise
Show with a counter-example that a ≡ b (mod 6) does not allow you to divide both sides by 2 and keep the modulus 6. Use a = 2 and b = 8.
Show answer
2 ≡ 8 (mod 6), because 8 − 2 = 6. Dividing both sides by 2 gives 1 and 4, and 4 − 1 = 3 is not a multiple of 6. So 1 ≢ 4 (mod 6). The congruence does survive if the modulus is also divided by 2: 1 ≡ 4 (mod 3).