Modular Arithmetic

Introduction

Throughout practicing many problems, you may have encountered problems of the following type:

Find the remainder when 320263^{2026} is divided by 77.

There exists an entire branch of mathematics centered around tackling such problems involving remainders, divisibility, etc. termed Modular Arithmetic.

Terminology

  • ab(modm)a \equiv b \pmod{m} (pronounced, "aa is congruent to bb modulo mm"): aa has the remainder, bb, when divided by mm.
  • Residue Classes: Modular arithmetic groups all integers into a finite set of "residues" based on their remainders. In modulo 5, every integer is essentially reduced to one of five values: {0,1,2,3,4}\{0, 1, 2, 3, 4\}

The Last Digit

Suppose you are solving a problem involving very large numbers, and you are asked to compute the last digit of the result. For instance:

Find the last digit of when 454545^{45}

Instead of dealing with the entire number 4545, we should only deal with its remainder modulo 1010, i.e, 55. Hence, the problem reduces to:

Find the last digit of when 5455^{45}

which is a lot easier as the last digit of any positive integral power of 55 is always 55.

Principles:

  • If ab(modm)a \equiv b \pmod{m} and pq(modm)p \equiv q \pmod{m}, then for all positive integers cc:
  1. a+cb+c(modm)a + c \equiv b + c \pmod{m}
  2. acbc(modm)a - c \equiv b - c \pmod{m}
  3. acbc(modm)ac \equiv bc \pmod{m}
  4. acbc(modm)a^{c} \equiv b^{c} \pmod{m}
  5. a+pb+q(modm)a + p \equiv b + q \pmod{m}
  6. apbq(modm)ap \equiv bq \pmod{m}

Tips:

  • When considering divisibility, move all terms to one side in a congruence equation. For instance, if: ab(modm)a \equiv b \pmod{m}, then: ab0(modm)a - b \equiv 0 \pmod{m}. This tells us that aba - b is divisible (if x0(mody)x \equiv 0 \pmod{y}, xx is divisible by yy) by mm which is a useful fact.
  • Given an nn-digit positive integer a1,a2,,ana_1, a_2, \ldots, a_n, we can 'expand' it to get: a110n1++ana_1 \cdot 10^{n-1} + \cdots + a_n. Now we can treat each term separately and consider its modulo some remainder, and sum all of them at the end. This is how divisiblity tricks are obtained!

Divisibility Tricks

For an nn-digit positive integer a1a2an=a110n1++an\overline{a_1 a_2 \ldots a_n} = a_1 \cdot 10^{n-1} + \cdots + a_n:

  • Divisible by 2 if an0(mod2)a_n \equiv 0 \pmod{2}, i.e. the last digit is even.
  • Divisible by 5 if an0(mod5)a_n \equiv 0 \pmod{5}, i.e. the last digit is 00 or 55.
  • Divisible by 4 if the last two digits form a number divisible by 44, since 1000(mod4)100 \equiv 0 \pmod{4}.
  • Divisible by 3 if a1+a2++an0(mod3)a_1 + a_2 + \cdots + a_n \equiv 0 \pmod{3}, i.e. the sum of digits is divisible by 33.
  • Divisible by 9 if a1+a2++an0(mod9)a_1 + a_2 + \cdots + a_n \equiv 0 \pmod{9}, i.e. the sum of digits is divisible by 99.
  • Divisible by 11 if a1a2+a30(mod11)a_1 - a_2 + a_3 - \cdots \equiv 0 \pmod{11}, i.e. the alternating digit sum is divisible by 1111.

Focus Problem:

Solution:

Let N=abc=100a+10b+cN = \overline{abc} = 100a + 10b + c where a{1,,9}a \in \{1, \ldots, 9\} and b,c{0,,9}b, c \in \{0, \ldots, 9\}.

The reversal of NN is cba=100c+10b+a\overline{cba} = 100c + 10b + a.

Condition 1: N0(mod7)N \equiv 0 \pmod{7}

Condition 2: cba0(mod5)\overline{cba} \equiv 0 \pmod{5}

Since cba\overline{cba} is divisible by 55, its last digit aa must satisfy a0(mod5)a \equiv 0 \pmod{5}, so a{5}a \in \{5\} (since a0a \neq 0, as NN is a three-digit number, and a=10a = 10 is impossible).

So a=5a = 5, meaning N=500+10b+cN = 500 + 10b + c.

Applying Condition 1:

500+10b+c0(mod7)500 + 10b + c \equiv 0 \pmod{7}

Since 500=717+3500 = 71 \cdot 7 + 3, we have 5003(mod7)500 \equiv 3 \pmod{7}, so:

10b+c34(mod7)10b + c \equiv -3 \equiv 4 \pmod{7}

We need to count pairs (b,c)(b, c) with b{0,,9}b \in \{0, \ldots, 9\}, c{0,,9}c \in \{0, \ldots, 9\} such that 10b+c4(mod7)10b + c \equiv 4 \pmod 7.

Note that 10b+c10b + c ranges over all integers from 00 to 9999. Among any 77 consecutive integers, exactly one is congruent to 4(mod7)4 \pmod{7}. Since 100=147+2100 = 14 \cdot 7 + 2, the values 0,1,,990, 1, \ldots, 99 contain:

  • 1414 complete cycles of 77, giving 1414 solutions.
  • A partial cycle {0,1}\{0, 1\} (i.e., 10b+c{98,99}10b + c \in \{98, 99\}), neither of which is 4(mod7)\equiv 4 \pmod{7}.

Therefore there are 14\boxed{14} three-digit integers satisfying both conditions.

Module Progress:

Join the AoPS Community!

Stuck on a problem, or don't understand a module? Join the AoPS community and get help from other math contest students.