1. Home
  2. Explore
  3. Mathematics
  4. Modular Arithmetic and Divisibility

Study methods

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

Modular Arithmetic and Divisibility

Divisibility and Modular Arithmetic

Congruence and remainders

For integers aaa and bbb, and a positive integer mmm, the statement

a≡b(modm)a \equiv b \pmod ma≡b(modm)

means that aaa and bbb have the same remainder when divided by mmm. Equivalently, their difference is divisible by mmm:

a≡b(modm)⟺m∣(a−b).a \equiv b \pmod m \quad\Longleftrightarrow\quad m \mid (a-b).a≡b(modm)⟺m∣(a−b).

Here, m∣(a−b)m \mid (a-b)m∣(a−b) means that a−ba-ba−b is an integer multiple of mmm.

Key idea: Modular arithmetic groups integers according to their remainders after division by a fixed positive integer.

Possible remainders

When dividing an integer by mmm, its remainder is one of

0,1,2,…,m−1.0,1,2,\ldots,m-1.0,1,2,…,m−1.

These are the only possible remainders when using the standard division algorithm. A remainder of mmm is equivalent to a remainder of 000, since mmm is exactly divisible by mmm.

For example, modulo 444, the possible remainders are 000, 111, 222, and 333. The remainders repeat in a cycle as the integers increase:

  • 0,4,8,…0,4,8,\ldots0,4,8,… have remainder 000 modulo 444.

  • 1,5,9,…1,5,9,\ldots1,5,9,… have remainder 111 modulo 444.

  • 2,6,10,…2,6,10,\ldots2,6,10,… have remainder 222 modulo 444.

  • 3,7,11,…3,7,11,\ldots3,7,11,… have remainder 333 modulo 444.

The same cycle continues through negative integers. For example, −1-1−1 has remainder 333 modulo 444, because −1-1−1 and 333 differ by −4-4−4, which is divisible by 444.

Testing congruence using divisibility

To check whether two integers are congruent modulo mmm, subtract them and test whether the difference is divisible by mmm.

For example,

2≡6(mod4)2 \equiv 6 \pmod 42≡6(mod4)

because

2−6=−4,2-6=-4,2−6=−4,

and 444 divides −4-4−4. The numbers 222 and 666 are not themselves divisible by 4;rather,theyarecongruentbecausetheirdifferenceisdivisibleby4; rather, they are congruent because their difference is divisible by4;rather,theyarecongruentbecausetheirdifferenceisdivisibleby4.Theyalsobothleaveremainder. They also both leave remainder.Theyalsobothleaveremainder2whendividedbywhen divided bywhendividedby4$.

In contrast,

24≢14(mod6)24 \not\equiv 14 \pmod 624≡14(mod6)

because 24−14=1024-14=1024−14=10, and 666 does not divide 101010. Equivalently, 242424 leaves remainder 000 modulo 666, while 141414 leaves remainder 222.


Congruence and the division algorithm

The division algorithm states that an integer can be written as a multiple of a positive integer plus a remainder. For an integer aaa and positive integer mmm, this has the form

a=qm+r,a=qm+r,a=qm+r,

where qqq is an integer and rrr is a remainder satisfying 0≤r<m0\le r<m0≤r<m. The remainder is also denoted by a mod ma \bmod mamodm.

Therefore, two integers are congruent modulo mmm exactly when their remainders are equal:

a≡b(modm)⟺a mod m=b mod m.a \equiv b \pmod m \quad\Longleftrightarrow\quad a \bmod m=b \bmod m.a≡b(modm)⟺amodm=bmodm.

For example:

  • 2=4⋅0+22=4\cdot 0+22=4⋅0+2, so 2 mod 4=22\bmod 4=22mod4=2.

  • 6=4⋅1+26=4\cdot 1+26=4⋅1+2, so 6 mod 4=26\bmod 4=26mod4=2.

The remainders agree, confirming that 2≡6(mod4)2\equiv 6\pmod 42≡6(mod4).

For another example:

  • 24=6⋅4+024=6\cdot 4+024=6⋅4+0, so 24 mod 6=024\bmod 6=024mod6=0.

  • 14=6⋅2+214=6\cdot 2+214=6⋅2+2, so 14 mod 6=214\bmod 6=214mod6=2.

The remainders differ, so 24≢14(mod6)24\not\equiv14\pmod 624≡14(mod6).

Three equivalent ways to recognize congruence

For integers a,ba,ba,b and positive integer mmm, the following statements are equivalent:

  1. a≡b(modm)a\equiv b\pmod ma≡b(modm).

  2. m∣(a−b)m\mid(a-b)m∣(a−b).

  3. a mod m=b mod ma\bmod m=b\bmod mamodm=bmodm.

Each gives a different practical way to check a congruence: compare the numbers’ remainders, or check whether their difference is divisible by the modulus.


Congruence as an equation involving an integer multiple

A useful equivalent formulation is

a≡b(modm)⟺a=b+km for some integer k.a\equiv b\pmod m \quad\Longleftrightarrow\quad a=b+km\text{ for some integer }k.a≡b(modm)⟺a=b+km for some integer k.

Proof

Suppose first that a≡b(modm)a\equiv b\pmod ma≡b(modm). By the definition of congruence, m∣(a−b)m\mid(a-b)m∣(a−b). By the definition of divisibility, there is an integer kkk such that

a−b=km.a-b=km.a−b=km.

Adding bbb to both sides gives

a=b+km.a=b+km.a=b+km.

For the reverse direction, suppose that a=b+kma=b+kma=b+km for some integer kkk. Subtracting bbb gives

a−b=km.a-b=km.a−b=km.

Thus m∣(a−b)m\mid(a-b)m∣(a−b), and so a≡b(modm)a\equiv b\pmod ma≡b(modm). This proves both directions of the equivalence.


Addition and multiplication preserve congruence

Let mmm be a positive integer. If

a≡b(modm)andc≡d(modm),a\equiv b\pmod m \quad\text{and}\quad c\equiv d\pmod m,a≡b(modm)andc≡d(modm),

then both of the following congruences hold:

a+c≡b+d(modm)a+c\equiv b+d\pmod ma+c≡b+d(modm)

and

ac≡bd(modm).ac\equiv bd\pmod m.ac≡bd(modm).

This means that numbers can be reduced to their remainders before adding or multiplying, provided the calculations are performed modulo the same positive integer.

Proof for addition

From the equation form of congruence, the assumptions imply that there are integers kkk and ℓ\ellℓ such that

a=b+kmandc=d+ℓm.a=b+km \quad\text{and}\quad c=d+\ell m.a=b+kmandc=d+ℓm.

Adding these equations gives

a+c=b+d+(k+ℓ)m.a+c=b+d+(k+\ell)m.a+c=b+d+(k+ℓ)m.

Thus (a+c)−(b+d)(a+c)-(b+d)(a+c)−(b+d) is a multiple of mmm, so

a+c≡b+d(modm).a+c\equiv b+d\pmod m.a+c≡b+d(modm).

Proof for multiplication

Using the same expressions for aaa and ccc,

ac=(b+km)(d+ℓm).ac=(b+km)(d+\ell m).ac=(b+km)(d+ℓm).

Expanding and collecting terms gives

ac=bd+m(bℓ+dk+kℓm).ac=bd+m(b\ell+dk+k\ell m).ac=bd+m(bℓ+dk+kℓm).

The difference ac−bdac-bdac−bd is therefore a multiple of mmm, so

ac≡bd(modm).ac\equiv bd\pmod m.ac≡bd(modm).

The addition and multiplication results are one-direction implications: if the original pairs are congruent modulo mmm, then their sums and products are congruent modulo mmm.


Computing with modular arithmetic

Calculations can be done either by evaluating the ordinary sum or product and then finding its remainder, or by reducing the numbers first and then carrying out the operation.

Addition modulo 555

Directly,

7+11=18≡3(mod5),7+11=18\equiv3\pmod 5,7+11=18≡3(mod5),

because 181818 leaves remainder 333 when divided by 555.

Alternatively,

7≡2(mod5)and11≡1(mod5),7\equiv2\pmod 5 \quad\text{and}\quad 11\equiv1\pmod 5,7≡2(mod5)and11≡1(mod5),

so the addition property gives

7+11≡2+1≡3(mod5).7+11\equiv2+1\equiv3\pmod 5.7+11≡2+1≡3(mod5).

Multiplication modulo 555

Directly,

7⋅11=77≡2(mod5).7\cdot11=77\equiv2\pmod 5.7⋅11=77≡2(mod5).

Alternatively, reducing the factors first gives

7⋅11≡2⋅1≡2(mod5).7\cdot11\equiv2\cdot1\equiv2\pmod 5.7⋅11≡2⋅1≡2(mod5).

Both methods produce the same remainder.

Notation for modular operations

The notation +m+_m+m​ indicates addition modulo mmm, while ×m\times_m×m​ indicates multiplication modulo mmm. The result is reduced to its remainder modulo mmm.

For example, modulo 333:

4+35≡9≡0(mod3),4+_3 5\equiv 9\equiv0\pmod 3,4+3​5≡9≡0(mod3),

since 999 is divisible by 333. For multiplication,

4×35≡20≡2(mod3),4\times_3 5\equiv20\equiv2\pmod 3,4×3​5≡20≡2(mod3),

since 202020 leaves remainder 222 when divided by 333.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent