← Back to Competition Math

Advanced Modular Arithmetic

Competition Math · AMC 10/12 LevelPreview

1. Introduction

Modular arithmetic is the art of doing arithmetic with remainders. Instead of tracking a giant number, you track only what it leaves behind when divided by some modulus mm. This is exactly the tool you need for the AMC/AIME staples: "what is the last digit of 720267^{2026}?", "what is the remainder when 31003^{100} is divided by 77?", or "find the smallest number leaving remainder 22 mod 33 and 33 mod 55." Each of these is hopeless by brute force but immediate once you think in residues.

The power of the subject comes from three landmark theorems. Fermat's Little Theorem and its generalization Euler's theorem let you shrink astronomical exponents down to size. The Chinese Remainder Theorem (CRT) lets you stitch together information from several coprime moduli into a single answer. Together with the basic rules that congruences respect addition and multiplication, these handle essentially every contest problem about powers, last digits, and systems of remainders.

This article develops the full machinery carefully: the definition and laws of congruence, modular inverses and when division is legal, Fermat and Euler with the totient function, order of an element, and CRT with a reliable solving procedure. Worked contest examples of rising difficulty show each tool in action.

2. Core Concepts

Concept 1 — Congruence and Its Definition

We write ab(modm)a \equiv b \pmod{m} to mean m(ab)m \mid (a - b), i.e. aa and bb leave the same remainder upon division by mm. Equivalently, a=b+kma = b + km for some integer kk. The modulus mm is always a positive integer in contest problems.

Concept 2 — Laws of Congruence

Congruence behaves like equality under the operations that matter:

  • If aba \equiv b and cd(modm)c \equiv d \pmod m, then a+cb+d(modm)a + c \equiv b + d \pmod m.
  • Under the same hypotheses, acbd(modm)ac \equiv bd \pmod m.
  • Consequently anbn(modm)a^n \equiv b^n \pmod m for any positive integer nn.

These laws let you replace any number by its residue before computing, keeping every intermediate value small.

Concept 3 — Residue Classes

The integers split into mm residue classes modulo mm, represented by 0,1,,m10, 1, \dots, m-1. Every integer is congruent to exactly one of these representatives. Working with residues is the whole point of modular arithmetic.

Concept 4 — Euler's Totient Function

Euler's totient φ(m)\varphi(m) counts how many integers from 11 to mm are coprime to mm. If m=p1e1pkekm = p_1^{e_1}\cdots p_k^{e_k}, then φ(m)=mi=1k(11pi).\varphi(m) = m\prod_{i=1}^{k}\left(1 - \frac{1}{p_i}\right). For a prime pp, φ(p)=p1\varphi(p) = p - 1; for a prime power, φ(pe)=pepe1\varphi(p^e) = p^e - p^{e-1}. The function is multiplicative: φ(mn)=φ(m)φ(n)\varphi(mn) = \varphi(m)\varphi(n) when gcd(m,n)=1\gcd(m,n) = 1.

Concept 5 — Modular Inverses

When gcd(c,m)=1\gcd(c, m) = 1, the element cc has a modular inverse c1c^{-1} with cc11(modm)c\cdot c^{-1} \equiv 1 \pmod m. Division by cc modulo mm means multiplication by c1c^{-1}. Find inverses via the extended Euclidean algorithm, by testing, or via Fermat: c1cp2(modp)c^{-1} \equiv c^{p-2} \pmod p for prime pp.

Concept 6 — When Cancellation Fails

You may cancel a factor cc from both sides of cacb(modm)ca \equiv cb \pmod m only if gcd(c,m)=1\gcd(c, m) = 1. If gcd(c,m)=g>1\gcd(c,m) = g > 1, cancellation is invalid and can produce wrong answers. The correct rule: cacb(modm)ab(modm/g)ca \equiv cb \pmod m \Rightarrow a \equiv b \pmod{m/g}.

Concept 7 — Fermat's Little Theorem

Fermat's Little Theorem. If pp is prime and pap \nmid a, then ap11(modp).a^{p-1} \equiv 1 \pmod p. Equivalently, for all integers aa, apa(modp)a^p \equiv a \pmod p. Fermat collapses exponents modulo p1p-1 when gcd(a,p)=1\gcd(a,p)=1.

Concept 8 — Euler's Theorem

Euler's Theorem. If gcd(a,m)=1\gcd(a, m) = 1, then aφ(m)1(modm).a^{\varphi(m)} \equiv 1 \pmod m. Fermat is the special case m=pm = p. Euler collapses exponents modulo φ(m)\varphi(m) when gcd(a,m)=1\gcd(a,m)=1.

Concept 9 — Order of an Element

The order of aa modulo mm, written ordm(a)\operatorname{ord}_m(a), is the smallest positive integer dd with ad1(modm)a^d \equiv 1 \pmod m. The order always divides φ(m)\varphi(m) (and divides p1p-1 for prime pp). Knowing the order gives the sharpest exponent reduction: aeaemodd(modm)a^e \equiv a^{e \bmod d} \pmod m.

Concept 10 — The Chinese Remainder Theorem

Chinese Remainder Theorem (CRT). If m1,,mrm_1, \ldots, m_r are pairwise coprime, the system xa1(modm1),,xar(modmr)x \equiv a_1 \pmod{m_1}, \quad \ldots, \quad x \equiv a_r \pmod{m_r} has a unique solution modulo M=m1m2mrM = m_1 m_2 \cdots m_r. CRT is the standard tool for last-digit problems (split mod 88 and mod 125125 for mod 10001000) and for recombining prime-power information.

Concept 11 — Last Digits as Modular Problems

The units digit of nn is nmod10n \bmod 10. The last two digits are nmod100n \bmod 100. The last three digits are nmod1000n \bmod 1000. For composite moduli like 100=425100 = 4 \cdot 25, solve mod each coprime factor and recombine with CRT.

Concept 12 — Splitting Composite Moduli

When m=m1m2m = m_1 m_2 with gcd(m1,m2)=1\gcd(m_1, m_2) = 1, solve a congruence modulo mm by solving it modulo m1m_1 and modulo m2m_2 separately, then recombining with CRT. This is often easier than working modulo mm directly, especially for m=35,100,1000m = 35, 100, 1000.

Continue reading with Premium

Upgrade to read the full article and unlock all Premium features.

Free

  • Unlimited practice — all difficulties
  • 3 hints / day
  • Community solutions
  • 2 timed mocks / month

Premium

  • Full article + all 57+ theory guides
  • Unlimited hints on practice problems
  • Unlimited timed mock exams & PDF worksheets
Log in