1. Home
  2. Explore
  3. Mathematics
  4. UK Mathematics Trust Webinar

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

UK Mathematics Trust Webinar

Modular Arithmetic

Congruence and Remainders

Modular arithmetic is a way of comparing numbers by their remainders after division by a fixed positive integer, called the modulus. For example, when working modulo 101010, numbers are compared according to their remainders upon division by 101010.

The notation

a≡b(modn)a \equiv b \pmod na≡b(modn)

is read as “aaa is congruent to bbb modulo nnn.” It means that aaa and bbb differ by a multiple of nnn:

n∣(a−b).n \mid (a-b).n∣(a−b).

Equivalently, aaa and bbb leave the same remainder when divided by nnn.

For instance, 324832483248 leaves remainder 888 when divided by 101010. This can be expressed in several equivalent ways:

  • 324832483248 and 320832083208 leave the same remainder when divided by 101010.

  • 324832483248 is 888 more than a multiple of 101010.

  • 3248=8+10k3248 = 8 + 10k3248=8+10k for some whole number kkk.

  • 3248−83248 - 83248−8 is divisible by 101010.

  • 101010 is a factor of 3248−83248 - 83248−8.

  • 3248≡8(mod10)3248 \equiv 8 \pmod {10}3248≡8(mod10).

These statements describe the same underlying relationship in different forms. The congruence notation is a compact shorthand for it.

Congruence is not ordinary equality

A congruence does not necessarily say that the two numbers are equal. It says they behave alike with respect to the chosen modulus. For example,

3248≡78(mod10),3248 \equiv 78 \pmod {10},3248≡78(mod10),

because 3248−78=31703248-78=31703248−78=3170, which is divisible by 101010. The numbers 324832483248 and 787878 are different, but they have the same remainder modulo 101010.

The remainder is usually written as one of the integers from 000 to n−1n-1n−1. However, the number on the right side of a congruence can be any integer in the same congruence class. Thus, modulo 333,

47≡2≡−1≡5≡8(mod3).47 \equiv 2 \equiv -1 \equiv 5 \equiv 8 \pmod 3.47≡2≡−1≡5≡8(mod3).

Each number differs from 474747 by a multiple of 333. In particular, 47−(−1)=4847-(-1)=4847−(−1)=48 is divisible by 333.

There are infinitely many integers congruent to a given number modulo nnn. By contrast, there are only nnn distinct remainder classes modulo nnn, usually represented by 0,1,…,n−10,1,\ldots,n-10,1,…,n−1.

Key definition: a≡b(modn)a \equiv b \pmod na≡b(modn) exactly when a−ba-ba−b is divisible by nnn.


Working with Congruences

Finding a congruence class

To reduce a number modulo nnn, find its remainder after division by nnn. For example,

47≡2(mod3),47 \equiv 2 \pmod 3,47≡2(mod3),

because 474747 leaves remainder 222 when divided by 333.

To compare two numbers, subtract them and test whether the difference is divisible by the modulus. For example,

47≢247(mod3),47 \not\equiv 247 \pmod 3,47≡247(mod3),

because 247−47=200247-47=200247−47=200 is not divisible by 333. Indeed, 474747 leaves remainder 222 modulo 333, while 247247247 leaves remainder 111.

A difference of zero is divisible by every nonzero integer: 0=n⋅00=n\cdot 00=n⋅0. Therefore, every number is congruent to itself modulo nnn.

Adding and multiplying modulo a number

Congruences can be used before carrying out a large calculation. If numbers are replaced by congruent numbers, their sums and products remain congruent modulo the same modulus. This makes it possible to simplify calculations while preserving the final remainder.

For example, modulo 444:

37≡1(mod4)and59≡−1(mod4).37 \equiv 1 \pmod 4 \quad\text{and}\quad 59 \equiv -1 \pmod 4.37≡1(mod4)and59≡−1(mod4).

Therefore,

37+59≡1+(−1)≡0(mod4).37+59 \equiv 1+(-1) \equiv 0 \pmod 4.37+59≡1+(−1)≡0(mod4).

This agrees with the direct calculation 37+59=9637+59=9637+59=96, which is divisible by 444.

For multiplication, the same reduction applies:

37⋅59≡1⋅(−1)≡−1≡3(mod4).37\cdot 59 \equiv 1\cdot(-1) \equiv -1 \equiv 3 \pmod 4.37⋅59≡1⋅(−1)≡−1≡3(mod4).

Thus the product leaves remainder 333 when divided by 444, without requiring the full multiplication.

The method is especially useful when numbers grow rapidly, such as when calculating a large power. Reducing modulo nnn at each step can keep intermediate values small, which is useful for hand calculations and computer calculations.


A Visual Model: Wrapping the Number Line

A useful way to picture arithmetic modulo nnn is to imagine the number line wrapped around a circle or cylinder with nnn positions.

For modulo 777, the positions correspond to the seven remainders 000 through 666. Starting at 000 and counting upward, each new group of seven returns to the same positions:

  • 777 lies above 000 because 7≡0(mod7)7 \equiv 0 \pmod 77≡0(mod7).

  • 888 lies above 111 because 8≡1(mod7)8 \equiv 1 \pmod 78≡1(mod7).

  • 141414 lies above 000 because 14≡0(mod7)14 \equiv 0 \pmod 714≡0(mod7).

  • Negative numbers wrap around in the other direction: −1≡6(mod7)-1 \equiv 6 \pmod 7−1≡6(mod7).

Numbers in the same position are congruent modulo 777. For example,

−7, 0, 7, 14, 21-7,\ 0,\ 7,\ 14,\ 21−7, 0, 7, 14, 21

are all congruent modulo 777. Similarly, −1,6,13,20-1,6,13,20−1,6,13,20 all belong to the same congruence class modulo 777.

This picture explains why there are only nnn different classes modulo nnn, even though infinitely many integers belong to each class.


Multiplication Tables Modulo a Number

A multiplication table modulo nnn records products by their congruence classes. It has nnn row headings and nnn column headings, usually 0,1,…,n−10,1,\ldots,n-10,1,…,n−1. Each product is reduced to its representative from that same set.

Multiplication table modulo 555

Using the headings 0,1,2,3,40,1,2,3,40,1,2,3,4, the rows are:

  • Row 000: 0,0,0,0,00,0,0,0,00,0,0,0,0

  • Row 111: 0,1,2,3,40,1,2,3,40,1,2,3,4

  • Row 222: 0,2,4,1,30,2,4,1,30,2,4,1,3

  • Row 333: 0,3,1,4,20,3,1,4,20,3,1,4,2

  • Row 444: 0,4,3,2,10,4,3,2,10,4,3,2,1

For example, 2⋅3=62\cdot 3=62⋅3=6, and 6≡1(mod5)6\equiv 1\pmod 56≡1(mod5), so the entry in row 222, column 333 is 111. The ordinary product is still 666; the table records its value modulo 555.

Likewise, 4⋅4=16≡1(mod5)4\cdot4=16\equiv1\pmod54⋅4=16≡1(mod5), so the bottom-right entry is 111.

Choosing the headings

Any one representative from each congruence class can be used as a heading. For a table modulo 555, possible sets include 0,1,2,3,40,1,2,3,40,1,2,3,4 or −2,−1,0,1,2-2,-1,0,1,2−2,−1,0,1,2. The headings need to represent each class exactly once.

Using 0,1,…,n−10,1,\ldots,n-10,1,…,n−1 makes it easy to compare and recognize patterns. Entries are normally reduced to these representatives; for example, 666 is written as 111 in a modulo-555 table because 6≡1(mod5)6\equiv1\pmod56≡1(mod5).

Patterns in the tables

Several patterns follow from the arithmetic:

  • Zero row and column: Multiplying any number by 000 gives 000, so the first row and first column contain only zeros.

  • Diagonal symmetry: The table is symmetric across the diagonal from the top-left to the bottom-right. This is because multiplication is commutative: a⋅b=b⋅aa\cdot b=b\cdot aa⋅b=b⋅a.

  • Final row and column: The last heading is n−1n-1n−1, which is congruent to −1-1−1 modulo nnn. Thus, multiplying by n−1n-1n−1 is equivalent to multiplying by −1-1−1, producing the negatives of the headings. In representatives 0,1,…,n−10,1,\ldots,n-10,1,…,n−1, this row and column count backward through the classes.

  • Repeated patterns: Rows may contain repeating sequences. For example, in the modulo-555 table, multiplying by 222 gives the row 0,2,4,1,30,2,4,1,30,2,4,1,3.

Patterns can depend on the modulus. For instance, modulo 101010, the result of a multiplication can be recorded using only its units digit, because two integers are congruent modulo 101010 exactly when they have the same units digit.

An additional symmetry modulo 555

The modulo-555 multiplication table also has a symmetry across the other diagonal, from the bottom-left to the top-right, when entries are arranged in the usual order. This is not the ordinary commutative symmetry.

For example, the entries 3⋅13\cdot13⋅1 and 4⋅24\cdot24⋅2 are both congruent to 333 modulo 555. Rewriting the headings in equivalent forms helps explain the pattern:

4≡−1(mod5)and2≡−3(mod5).4\equiv-1\pmod5 \quad\text{and}\quad 2\equiv-3\pmod5.4≡−1(mod5)and2≡−3(mod5).

So 4⋅24\cdot24⋅2 is congruent to (−1)(−3)=3(-1)(-3)=3(−1)(−3)=3, matching 3⋅1=33\cdot1=33⋅1=3. The pattern comes from the way negative representatives interact modulo 555. Similar patterns can be investigated in tables for other moduli rather than assumed to occur identically in every case.


Divisibility Tests and Squares

Modular arithmetic explains familiar divisibility rules. In base ten, the powers of 101010 satisfy

10≡1(mod9).10 \equiv 1 \pmod 9.10≡1(mod9).

A number written with decimal digits can therefore be replaced modulo 999 by the sum of its digits. For example, the number 324832483248 is congruent modulo 999 to

3+2+4+8=17,3+2+4+8=17,3+2+4+8=17,

and 17≡8(mod9)17\equiv8\pmod917≡8(mod9). Consequently, a number and the sum of its digits have the same remainder modulo 999. This gives the usual test for divisibility by 9‘;thesamereasoningalsosupportsthetestfordivisibilityby9`; the same reasoning also supports the test for divisibility by9‘;thesamereasoningalsosupportsthetestfordivisibilityby3$.

Multiplication tables can also help rule out whether a number is a square. A square modulo nnn must appear among the products of a number by itself, found on the main diagonal of the multiplication table. For example, modulo 444, the possible square remainders are only 000 and 111:

02≡0,12≡1,22≡0,32≡1(mod4).0^2\equiv0,\quad 1^2\equiv1,\quad 2^2\equiv0,\quad 3^2\equiv1\pmod4.02≡0,12≡1,22≡0,32≡1(mod4).

Therefore, an integer congruent to 222 or 333 modulo 444 cannot be a perfect square. Checking several moduli can give stronger ways to rule out a proposed square.


Further Uses

Modular arithmetic appears in mathematics, computing, and cryptography.

  • Large calculations: Repeated reduction modulo a fixed number prevents intermediate values from becoming unnecessarily large.

  • Cryptography: Encryption and decryption systems use modular arithmetic to transform numbers while allowing intended users to recover the original information. The RSA cryptosystem is a widely used example whose operations involve modular exponentiation.

  • Remainder constraints: A problem may specify the remainders of an unknown number upon division by several different integers. The Chinese remainder theorem describes when such conditions can be combined into a solution, especially when the moduli are pairwise coprime.

  • Prime moduli: Fermat’s little theorem is a result about powers modulo a prime. If ppp is prime and ppp does not divide aaa, then

    ap−1≡1(modp).a^{p-1}\equiv1\pmod p.ap−1≡1(modp).

    It is useful in number theory and is related to methods used in modular computation and cryptography.

The same core idea underlies all these applications: integers can be replaced by simpler representatives of their congruence classes whenever the calculation only depends on the remainder.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent