Skip to content
Number Theory · Chapter 20

Modular Arithmetic

Work with remainders instead of giant numbers: wrap around a clock dial, find last digits of huge powers, and combine remainder conditions.

You'll need
open on YouTube
20.10%

Modular Arithmetic Fundamentals

In this section you will be able to write remainders as congruences, and use negative remainders when they are easier.

It is 10 o’clock. What time will it be in 5 hours? Not 15 o’clock! The clock wraps around, so it is 3 o’clock.

A clock only remembers the remainder. Modular arithmetic does the same with any number of spots on the dial. When two numbers land on the same spot, you say they are congruent.

Look:a number just below a full lap is a small negative. On a 6-spot dial, 5 is one step before 0, so it is also −1.

Exploreplay first, formulas later

17 = 2 × 6 + 5, so 17 ≡ 5 (mod 6)

mod m6
a17
012345
The big numbers
17 = 2 × 6 + 5 ≡ 5 (mod 6)
17 = 2 × 6 + 5, so 17 ≡ 5 (mod 6)

17 = 2 × 6 + 5, so 17 ≡ 5 (mod 6)

Name it

Definition 20.1.1 · Congruence

n≡a(modb)n \equiv a \pmod{b}

means the number nn leaves the same remainder as aa when divided by bb.

Remark 20.1.2

Mods can also be negative. For example a number that is 5(mod6)5 \pmod{6} is also −1(mod6)-1 \pmod{6}. This can be useful for simplifying calculations when raising this number to large powers.

Checkpoint for section 20.1

Get 2 of 3 right to master this section. One try each, no hints.
1

What is 47(mod6)47 \pmod{6}? (The remainder when 47 is divided by 6.)

2

A number is 7(mod8)7 \pmod{8}. Which negative number between −8-8 and 00 is it also congruent to, mod 8?

3

Find aa between 0 and 6 with 100≡a(mod7)100 \equiv a \pmod{7}.

20.20%

Product Rule

In this section you will be able to multiply remainders instead of big numbers, to find last digits and remainders fast.

What is the units digit of 23 × 47? You could multiply it all out. Or you could just multiply 3 × 7 = 21. The answer is 1 either way!

The product rule says you can swap each number for its remainder before you multiply. The last digit of a product depends only on the last digits of the factors.

Look:this works for the last two digits (mod 100) or the last three (mod 1000) too.

Exploreplay first, formulas later

23 × 47 = 1081 ≡ 1 (mod 10); 3 × 7 = 21 ≡ 1 (mod 10)

mod m10
a23
b47
0123456789
The big numbers
23 × 47 = 1,081 ≡ 1 (mod 10)
Swap in the remainders first
3 × 7 = 21 ≡ 1 (mod 10)

Same spot on the dial! You never needed the big numbers.

23 × 47 = 1081 ≡ 1 (mod 10)

23 × 47 = 1081 ≡ 1 (mod 10); 3 × 7 = 21 ≡ 1 (mod 10)

Name it

Theorem 20.2.1 · Product Rule

If a≡x(modn)a \equiv x \pmod{n} and b≡y(modn)b \equiv y \pmod{n}, then

ab≡xy(modn)ab \equiv xy \pmod{n}

Watch itpredict, then reveal

Example 20.1

AMC 8

If nn is an even positive integer, the double factorial notation n!!n!! represents the product of all the even integers from 2 to nn. For example, 8!!=2⋅4⋅6⋅88!! = 2 \cdot 4 \cdot 6 \cdot 8. What is the units digit of the following sum?

2!!+4!!+6!!+⋯+2018!!+2020!!+2022!!2!! + 4!! + 6!! + \cdots + 2018!! + 2020!! + 2022!!

48 × 8 = 384 ≡ 4 (mod 10); 8 × 8 = 64 ≡ 4 (mod 10)

0123456789
The big numbers
48 × 8 = 384 ≡ 4 (mod 10)
Swap in the remainders first
8 × 8 = 64 ≡ 4 (mod 10)

Same spot on the dial! You never needed the big numbers.

48 × 8 = 384 ≡ 4 (mod 10)

48 × 8 = 384 ≡ 4 (mod 10); 8 × 8 = 64 ≡ 4 (mod 10)

  1. 1

    Look at 10!!=2⋅4⋅6⋅8⋅1010!! = 2 \cdot 4 \cdot 6 \cdot 8 \cdot 10. What is its units digit?

    Predict first:
open on YouTube

Example 20.2

AIME

Find the remainder when 9×99×999×⋯×99⋯9⏟999 9’s9 \times 99 \times 999 \times \cdots \times \underbrace{99\cdots9}_{\text{999 9's}} is divided by 1000.

999 × 9999 = 9989001 ≡ 1 (mod 1000); 999 × 999 = 998001 ≡ 1 (mod 1000)

1 = -9990 (mod 1000)
The big numbers
999 × 9,999 = 9,989,001 ≡ 1 (mod 1000)
Swap in the remainders first
999 × 999 = 998,001 ≡ 1 (mod 1000)

Same spot on the dial! You never needed the big numbers.

999 × 9999 = 9989001 ≡ 1 (mod 1000)

999 × 9999 = 9989001 ≡ 1 (mod 1000); 999 × 999 = 998001 ≡ 1 (mod 1000)

  1. 1

    The product rule lets you find each term (mod1000)\pmod{1000} and multiply. 9≡99 \equiv 9 and 99≡9999 \equiv 99. What is 999(mod1000)999 \pmod{1000}? Write it as a negative number.

    Predict first:

Contest cornerreal contest problems

Problem 20.6.6

AMC 8

The product of the two 99-digit numbers 303,030,303,…,030,303303{,}030{,}303{,}\ldots{,}030{,}303 and 505,050,505,…,050,505505{,}050{,}505{,}\ldots{,}050{,}505 has thousands digit AA and units digit BB. What is the sum of AA and BB?

Problem 20.6.13(additional)

AMC 8

If nn is an even positive integer, the double factorial notation n!!n!! represents the product of all the even integers from 2 to nn. For example, 8!!=2⋅4⋅6⋅88!! = 2 \cdot 4 \cdot 6 \cdot 8. What is the units digit of the following sum?

2!!+4!!+6!!+⋯+2018!!+2020!!+2022!!2!! + 4!! + 6!! + \cdots + 2018!! + 2020!! + 2022!!

Problem 20.6.14(additional)

MATHCOUNTS

Find the remainder when 12+22+32+⋯+201621^2 + 2^2 + 3^2 + \cdots + 2016^2 is divided by 17.

Checkpoint for section 20.2

Get 2 of 3 right to master this section. One try each, no hints.
1

What is the units digit of 23×4723 \times 47?

2

What is the remainder when 101×102×103101 \times 102 \times 103 is divided by 100?

3

What is the remainder when 17×1917 \times 19 is divided by 9?

20.30%

Exponent Rule

In this section you will be able to find remainders of huge powers by swapping the base for a small remainder.

1999 to the power 2000 has more than 6000 digits. You can still find its remainder when divided by 5 in your head!

A power is just the same number multiplied again and again. So the product rule works for powers too: swap the base for its remainder. A remainder of 1 or −1 is the best kind, since its powers are so easy.

Exploreplay first, formulas later

1999^k mod 5 repeats 4, 1 (length 2); 1999^2000 ≡ 1999^2 ≡ 1 (mod 5)

base1999
mod5
01234
  1. 199911999^{1}4
  2. 199921999^{2}1
  3. 199931999^{3}4
  4. 199941999^{4}1
  5. 199951999^{5}4
  6. 199961999^{6}1

The remainder mod 5s repeat every 2 powers: 4, 1.

cycle length 2

1999^k mod 5 repeats 4, 1 (length 2)

Name it

Theorem 20.3.1 · Exponent Rule

If a≡x(modn)a \equiv x \pmod{n}, then

am≡xm(modn)a^m \equiv x^m \pmod{n}

Watch itpredict, then reveal

Example 20.3

AMC 8

When 199920001999^{2000} is divided by 5, what is the remainder?

1999^2000 ≡ 1 (mod 5); 4^2000 ≡ 1 (mod 5)

01234
The big numbers
199920001999^{2000} ≡ 1 (mod 5)
Swap in the remainders first
42000^{2000} ≡ 1 (mod 5)

Same spot on the dial! You never needed the big numbers.

1999^2000 ≡ 1 (mod 5)

1999^2000 ≡ 1 (mod 5); 4^2000 ≡ 1 (mod 5)

  1. 1

    What mod value is equivalent to 1999(mod5)1999 \pmod{5}?

    Predict first:

Example 20.4

Find the remainder of 989^8 when it's divided by 100.

9^k mod 100 repeats 9, 81, 29, 61, 49, 41, 69, 21, 89, 1 (length 10)

  1. 919^{1}9
cycle length 10

9^k mod 100 repeats 9, 81, 29, 61, 49, 41, 69, 21, 89, 1 (length 10)

  1. 1

    Start small. What is 929^2?

    Predict first:
open on YouTube

Contest cornerreal contest problems

Problem 20.6.3

AMC 8

What is the tens digit of 720117^{2011}?

Checkpoint for section 20.3

Get 2 of 3 right to master this section. One try each, no hints.
1

What is the remainder when 115011^{50} is divided by 5?

2

What is the remainder when 8258^{25} is divided by 9?

3

What is the remainder when 109910^{99} is divided by 9?

20.40%

Multiple Modular Congruences

In this section you will be able to combine two or more remainder conditions into one.

Sejal has some marbles. In rows of 5, one is left over. In rows of 7, one is left over again. How many marbles could she have?

Each condition is a sieve: it lets through every 3rd, or every 5th, number. Put two sieves together and the survivors are evenly spaced again. The gap is the LCM of the mods.

Look:if every remainder is the same (or the same distance below the divisor), you can subtract it and use the LCM straight away.

Exploreplay first, formulas later

0 to 100, x ≡ 2 (mod 3) and ≡ 4 (mod 5): 14, 29, 44, 59, 74, 89; together: x ≡ 14 (mod 15)

remainder 12
mod 13
remainder 24
mod 25
14, 29, 44, 59, 74, 89every 15 apart

0 to 100, x ≡ 2 (mod 3) and ≡ 4 (mod 5): 14, 29, 44, 59, 74, 89; together: x ≡ 14 (mod 15)

Name it

Concept 20.4.1 · Combining Mods

We can generally combine different mods together. For example, if x≡1(mod5)x \equiv 1 \pmod{5} and x≡1(mod7)x \equiv 1 \pmod{7}, then x≡1(mod35)x \equiv 1 \pmod{35}.

Watch itpredict, then reveal

Example 20.5

Find the largest possible number less than 100 that leaves a remainder of 1 when divided by 5 and a remainder of 1 when divided by 7.

0 to 100, x ≡ 1 (mod 5) and ≡ 1 (mod 7): 1, 36, 71; together: x ≡ 1 (mod 35)

1, 36, 71every 35 apart

0 to 100, x ≡ 1 (mod 5) and ≡ 1 (mod 7): 1, 36, 71; together: x ≡ 1 (mod 35)

  1. 1

    Rewrite the conditions as x≡1(mod5)x \equiv 1 \pmod{5} and x≡1(mod7)x \equiv 1 \pmod{7}. Then what is x−1(mod5)x - 1 \pmod{5} and (mod7)\pmod{7}?

    Predict first:

Example 20.6

Find the smallest positive integer that leaves a remainder of 5 when divided by 6, 2 when divided by 5, 2 when divided by 7, and 2 when divided by 11.

1100 to 1199, x ≡ 5 (mod 6): 1103, 1109, 1115, 1121, 1127, 1133, 1139, 1145, …; together: x ≡ 5 (mod 6)

1103, 1109, 1115, 1121, 1127, 1133, 1139, …every 6 apart

1100 to 1199, x ≡ 5 (mod 6): 1103, 1109, 1115, 1121, 1127, 1133, 1139, 1145, …; together: x ≡ 5 (mod 6)

  1. 1

    Three conditions share the remainder 2. If xx leaves 2 when divided by 5, 7 and 11, what is x−2x - 2 a multiple of?

    Predict first:
open on YouTube

Try it

Problem 20.6.4

What is the smallest number greater than 2 that leaves a remainder of 2 when divided by 3, 4, 5, or 6?

Problem 20.6.10(additional)

Find the smallest positive number greater than 1 that leaves a remainder of 1 when divided by 2, by 3, by 4, by 5, and by 6.

Contest cornerreal contest problems

Problem 20.6.5

AMC 8

The number NN is a two-digit number.

  • When NN is divided by 99, the remainder is 11.
  • When NN is divided by 1010, the remainder is 33.

What is the remainder when NN is divided by 1111?

Problem 20.6.7

AMC 8

How many positive three-digit integers have a remainder of 2 when divided by 6, a remainder of 5 when divided by 9, and a remainder of 7 when divided by 11?

Problem 20.6.11(additional)

AMC 8

How many positive integers can fill the blank in the sentence below?

“One positive integer is _____ more than twice another, and the sum of the two numbers is 28.”

Checkpoint for section 20.4

Get 2 of 3 right to master this section. One try each, no hints.
1

Find the smallest positive number greater than 1 that leaves a remainder of 1 when divided by 2, by 3, by 4, by 5, and by 6.

2

What is the smallest positive number that leaves a remainder of 2 when divided by 3 and a remainder of 4 when divided by 5?

3

How many numbers from 1 to 100 leave a remainder of 1 when divided by 4 and also when divided by 6?

20.50%

Digit Cycles

In this section you will be able to find the last digit of a huge power by spotting the cycle.

What is the last digit of 2 to the power 1026? Nobody wants to multiply 2 by itself 1026 times. Luckily, the last digits repeat!

Each new last digit depends only on the one before it. So once a last digit shows up again, the whole pattern repeats. Find the cycle length, then divide the big exponent by it and use the remainder.

Look:if the remainder is 0, you land on the last spot of the cycle, not the first.

Exploreplay first, formulas later

2^k mod 10 repeats 2, 4, 8, 6 (length 4)

base2
mod10
0123456789
  1. 212^{1}2
  2. 222^{2}4
  3. 232^{3}8
  4. 242^{4}6
cycle length 4

2^k mod 10 repeats 2, 4, 8, 6 (length 4)

Name it

Concept 20.5.1 · Digit Cycles

To calculate large digit(s) of a number aba^b, a strategy that may work is to just look for a pattern by computing the first few values of aba^b and then seeing that the pattern will repeat for large values of bb.

Watch itpredict, then reveal

Example 20.7

Find the units digit of 210262^{1026}

2^k mod 10 repeats 2, 4, 8, 6 (length 4); 2^1026 ≡ 2^2 ≡ 4 (mod 10)

0123456789
  1. 212^{1}2
  2. 222^{2}4
  3. 232^{3}8
  4. 242^{4}6
cycle length 4

2^k mod 10 repeats 2, 4, 8, 6 (length 4)

  1. 1

    10261026 is a very large power, so try smaller ones. 21,22,23,242^1, 2^2, 2^3, 2^4 end in 2,4,8,62, 4, 8, 6. What is the units digit of 25=322^5 = 32?

    Predict first:

Example 20.8

Find the remainder when

(151+152+153+⋯+152022)+(341+342+⋯+342021)(15^1 + 15^2 + 15^3 + \cdots + 15^{2022}) + (34^1 + 34^2 + \cdots + 34^{2021})

is divided by 7.

15^k mod 7 repeats 1 (length 1)

0123456
  1. 15115^{1}1
  2. 15215^{2}1
  3. 15315^{3}1
  4. 15415^{4}1
  5. 15515^{5}1
  6. 15615^{6}1

The remainder mod 7s repeat every 1 powers: 1.

cycle length 1

15^k mod 7 repeats 1 (length 1)

  1. 1

    What is 15(mod7)15 \pmod{7}? Then what is every 15k(mod7)15^k \pmod{7}?

    Predict first:
open on YouTube

Try it

Problem 20.6.2

What is the units digit of 1919+999919^{19} + 99^{99}?

Problem 20.6.8(additional)

What is the units digit of 1317+171313^{17} + 17^{13}?

Problem 20.6.9(additional)

Find the units digit of 7109−33367^{109} - 3^{336}

Contest cornerreal contest problems

Problem 20.6.1

AMC 8

What is the units digit of 13201213^{2012}?

Problem 20.6.12(additional)

AMC 10/12

The Fibonacci sequence 1,1,2,3,5,8,13,21,…1, 1, 2, 3, 5, 8, 13, 21, \ldots starts with two 1s, and each term afterwards is the sum of its two predecessors. Which one of the ten digits is the last to appear in the units position of a number in the Fibonacci sequence?

(A) 0 · (B) 4 · (C) 6 · (D) 7 · (E) 9

Problem 20.6.16(additional)

Omega Learn

In the Fibonacci sequence, how many of the first 100 terms in the sequence leave a remainder of less than 7 when divided by 8?

Checkpoint for section 20.5

Get 2 of 3 right to master this section. One try each, no hints.
1

What is the units digit of 1317+171313^{17} + 17^{13}?

2

What is the units digit of 420234^{2023}?

3

What is the units digit of 31003^{100}?

20.6

Practice Problems

In this section you will be able to mix the product rule, cycles and combined mods on contest problems.

One more tough one, from the AIME! Pair up the squares, simplify, and only then reduce mod 1000. Every problem has three hints if you get stuck.

Want every problem from this chapter on one page? Open the problem set.

Contest cornerreal contest problems

Problem 20.6.15(additional)

AIME

Let N=1002+992−982−972+962+⋯+42+32−22−12N = 100^2 + 99^2 - 98^2 - 97^2 + 96^2 + \cdots + 4^2 + 3^2 - 2^2 - 1^2, where the additions and subtractions alternate in pairs. Find the remainder when NN is divided by 1000.