WDC Learn

Number Theory

Divisibility and digit problems, primes and factorisation, gcd and lcm with the Euclidean algorithm, divisor counting and sums, modular arithmetic with inverses, Fermat, Euler and the Chinese Remainder Theorem, last digits and cycles, number bases, and Diophantine equations.

≈4–5 problems per paper10 lessons6 worked examples30 practice problems4 videos

Number theory is the most reliable source of AMC 12 points for a student who has learned the right tools, because nearly every problem reduces to a small, exact computation once the correct idea is applied. The early problems (#1–#10) test divisibility, factorisation and counting with exponents. These are routine once the prime factorisation is written down, and mistakes come from careless counting rather than missing ideas.

From about #11 onwards the problems combine ideas. A typical middle-level question asks for a remainder of a huge power, a count of divisors with a constraint, or a base conversion that must be solved for an unknown. The solution is a chain: factor, reduce modulo the right number, apply Fermat or Euler to shrink an exponent, and then count. The hard problems (#20–#25) use the same tools but demand a better choice of modulus or a factorisation that is not obvious, such as splitting a modulus with CRT or rearranging a Diophantine equation into a product.

To study the topic, learn the concepts in order, and for each one do a few problems by hand before checking with a computer. Keep a notebook of factorisations of numbers you meet often (for example 360360, 20252025, 10001000), because fast recognition of their prime structure saves minutes on every test. Then practise problems mixing several concepts, since real contest questions rarely announce which tool is needed.

Helpful first: Algebraic Manipulation

1.Divisibility and digit sums

We write b∣ab \mid a when a=bka = bk for some integer kk. Divisibility is preserved by sums and differences. If a=dxa = dx and b=dyb = dy, then a+b=d(x+y)a + b = d(x+y) and a−b=d(x−y)a - b = d(x-y), so d∣ad \mid a and d∣bd \mid b force d∣(a+b)d \mid (a+b) and d∣(a−b)d \mid (a-b). This closure is what makes divisibility tests work: you only need the remainders of the pieces of a number, not the number itself.

The test for 99 comes from one observation, 10=9+110 = 9 + 1, so 10≡1(mod9)10 \equiv 1 \pmod 9. Writing N=∑idi10iN = \sum_i d_i 10^i and reducing each power of 1010 gives N≡∑idi(mod9)N \equiv \sum_i d_i \pmod 9. So NN and its digit sum leave the same remainder on division by 99. For example 385=9⋅42+7385 = 9 \cdot 42 + 7, and 3+8+5=16≡7(mod9)3 + 8 + 5 = 16 \equiv 7 \pmod 9. The same argument with 10≡1(mod3)10 \equiv 1 \pmod 3 gives the test for 33.

The test for 1111 uses 10≡−1(mod11)10 \equiv -1 \pmod{11}. Each digit in an odd position gets weight +1+1 and each digit in an even position gets weight −1-1, so NN and its alternating digit sum agree mod 1111. For 385=11⋅35385 = 11 \cdot 35, the alternating sum is 5−8+3=05 - 8 + 3 = 0, as it must be.

Tests for 44 and 88 depend only on the last few digits, because 100=4⋅25100 = 4 \cdot 25 and 1000=8⋅1251000 = 8 \cdot 125. More generally, 10k10^k is a multiple of 2k2^k and 5k5^k, so the last kk digits decide divisibility by 2k2^k and 5k5^k alone.

Digit problems are counting problems about strings of digits. Write the number as d1d2⋯dkd_1 d_2 \cdots d_k, translate each condition into a statement about neighbouring digits, and count with the multiplication principle. A condition such as “the digits are strictly increasing” is really a choice of a set: a strictly increasing string is determined by the set of digits it uses, so kk-digit strings from {0,…,9}\{0, \ldots, 9\} with this property correspond to (10k)\binom{10}{k} subsets. Leading zeros must be handled separately, since a string starting with 00 is not a kk-digit number.

KEY FACTS
  • b∣ab \mid a means a=bka = bk for some integer kk; if d∣ad \mid a and d∣bd \mid b then d∣(a±b)d \mid (a \pm b)
  • N≡(digit sum of N)(mod9)N \equiv (\text{digit sum of } N) \pmod 9, so 9∣N9 \mid N exactly when 99 divides the digit sum
  • N≡(alternating digit sum of N)(mod11)N \equiv (\text{alternating digit sum of } N) \pmod{11}
  • Divisibility by 2k2^k or 5k5^k depends only on the last kk digits

Spot it: The problem asks whether a number is a multiple of something, asks for the remainder of a very long number, or counts digit strings that satisfy a digit condition.

COMMON MISTAKES
  • Treating the digit sum as the remainder itself; it is only congruent to NN modulo 99, and can be much larger than 99
  • Checking only the last digit for divisibility by 44 or 88, which needs the last two or three digits
  • Counting a digit string with a leading zero as if it were a number with that many digits
TRY IT

Find the remainder when the 100100-digit number consisting of 100100 sevens is divided by 99.

Practise this lesson (6 problems) →

2.Primes and factorisation

A prime is an integer greater than 11 whose only positive divisors are 11 and itself. The first primes are 2,3,5,7,11,13,…2, 3, 5, 7, 11, 13, \ldots. The number 11 is neither prime nor composite. The Fundamental Theorem of Arithmetic says every integer n>1n > 1 can be written as a product of primes, n=p1a1p2a2⋯pkakn = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}, and this representation is unique apart from the order of the factors. The exponents form a fingerprint for nn: they determine every divisor, every square factor and every gcd.

Why does the representation exist? If n>1n > 1 is not prime, it has a divisor dd with 1<d<n1 < d < n, and we can split n=d⋅(n/d)n = d \cdot (n/d) and repeat with both pieces. Since each step makes the pieces smaller, the process stops, and it stops only at primes. Uniqueness is slightly harder, but it follows from Euclid's lemma: if a prime pp divides abab, then p∣ap \mid a or p∣bp \mid b.

To factor a number by hand, divide by 22 as often as possible, then by 33, 55, 77 and so on. You can stop once the square of the current prime exceeds what remains, because a composite number always has a prime factor no larger than its square root; the leftover is then prime or 11. For example 360=2⋅180=22⋅90=23⋅45=23⋅32⋅5360 = 2 \cdot 180 = 2^2 \cdot 90 = 2^3 \cdot 45 = 2^3 \cdot 3^2 \cdot 5.

Primes are also the building blocks of divisibility questions. A number mm divides nn exactly when every prime in mm appears in nn with at least the same exponent. Problems that ask “how many divisors”, “what is the largest square dividing NN” or “what is the least common multiple” are all answered by reading exponents off the factorisation.

A useful habit is to factor large expressions such as 38−13^8 - 1 using difference-of-squares and sum-of-powers identities. For instance 38−1=(34−1)(34+1)3^8 - 1 = (3^4 - 1)(3^4 + 1), and each factor splits again, which exposes the prime divisors without a calculator.

KEY FACTS
  • Fundamental Theorem: n=p1a1⋯pkakn = p_1^{a_1}\cdots p_k^{a_k} is unique up to the order of the factors
  • 11 is neither prime nor composite
  • A composite nn always has a prime factor p≤np \le \sqrt{n}
  • a2−b2=(a−b)(a+b)a^2 - b^2 = (a-b)(a+b) and an−1a^n - 1 factors through ad−1a^d - 1 for each divisor dd of nn

Spot it: The problem involves a product, a perfect power, the prime divisors of a large number, or any count that depends on how many times each prime appears.

COMMON MISTAKES
  • Stopping trial division at the number itself rather than at its square root
  • Forgetting that 11 is not prime, which changes sums of primes and counts of prime divisors
  • Assuming a number is prime because it has no small prime factor up to n3\sqrt[3]{n} rather than n\sqrt{n}
TRY IT

What is the largest prime factor of 38−13^8 - 1?

Practise this lesson (6 problems) →

3.GCD, LCM and the Euclidean algorithm

The greatest common divisor gcd⁡(a,b)\gcd(a,b) is the largest integer dividing both aa and bb. The least common multiple lcm⁡(a,b)\operatorname{lcm}(a,b) is the smallest positive integer that both aa and bb divide. With prime factorisations both are read off prime by prime: the gcd takes the smaller exponent and the lcm takes the larger. For 12=22⋅312 = 2^2 \cdot 3 and 18=2⋅3218 = 2 \cdot 3^2 we get gcd⁡=2⋅3=6\gcd = 2 \cdot 3 = 6 and lcm⁡=22⋅32=36\operatorname{lcm} = 2^2 \cdot 3^2 = 36.

Factoring large numbers is slow, but the Euclidean algorithm finds the gcd quickly, and it rests on one lemma: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b) = \gcd(b, a \bmod b). To see why, write a=qb+ra = qb + r with r=a mod br = a \bmod b. Any common divisor of aa and bb divides r=a−qbr = a - qb, and any common divisor of bb and rr divides a=qb+ra = qb + r. So the two pairs (a,b)(a,b) and (b,r)(b,r) have exactly the same common divisors, and therefore the same greatest one.

Iterating the lemma gives the algorithm: replace (a,b)(a,b) by (b,a mod b)(b, a \bmod b) until the remainder is 00; the last nonzero number is the gcd. For 252252 and 105105: 252=2⋅105+42252 = 2 \cdot 105 + 42, 105=2⋅42+21105 = 2 \cdot 42 + 21, 42=2⋅2142 = 2 \cdot 21, so gcd⁡(252,105)=21\gcd(252,105) = 21. The same chain of equations can be run backwards to write the gcd as an integer combination 21=105−2⋅42=…21 = 105 - 2 \cdot 42 = \ldots, which is the extended Euclidean algorithm and is the source of modular inverses.

The two functions are linked by gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b) \cdot \operatorname{lcm}(a,b) = ab. For each prime, the smaller and the larger exponent add up to the sum of the two original exponents, so the identity holds prime by prime.

On the contest, gcd and lcm arise whenever two things repeat with different periods, when a rectangle is tiled by the largest possible squares, or when a condition holds for two different reasons at once. In each case, reduce the problem to a gcd or lcm and then compute it by factoring or by Euclid.

KEY FACTS
  • gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b) \cdot \operatorname{lcm}(a,b) = ab for positive integers aa and bb
  • gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b) = \gcd(b, a \bmod b), and gcd⁡(a,0)=a\gcd(a,0) = a
  • If gcd⁡(a,b)=1\gcd(a,b) = 1 then aa and bb are relatively prime and gcd⁡(a,bc)=gcd⁡(a,c)\gcd(a, bc) = \gcd(a,c) for every cc
  • Two repeating cycles of lengths aa and bb coincide again after lcm⁡(a,b)\operatorname{lcm}(a,b) steps

Spot it: The problem asks for a largest common divisor, a shared multiple, the largest equal piece that fits exactly into two lengths, or the moment two periodic events line up.

COMMON MISTAKES
  • Taking the gcd of the numbers' sum or difference instead of the numbers themselves
  • Multiplying the lcm of three numbers pairwise without checking that the common factors are not double-counted
  • Confusing gcd⁡(a,b)=1\gcd(a,b)=1 with aa and bb being prime
TRY IT

Find gcd⁡(1071,462)\gcd(1071, 462) using the Euclidean algorithm.

Practise this lesson (3 problems) →

4.Divisor counting and divisor sums

Suppose n=p1a1p2a2⋯pkakn = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}. Every divisor of nn has the form p1e1⋯pkekp_1^{e_1} \cdots p_k^{e_k} with 0≤ei≤ai0 \le e_i \le a_i, and distinct exponent tuples give distinct divisors because the factorisation is unique. For each prime there are ai+1a_i + 1 choices, and the choices for different primes are independent, so the number of divisors is d(n)=(a1+1)(a2+1)⋯(ak+1).d(n) = (a_1+1)(a_2+1)\cdots(a_k+1). For example 360=23⋅32⋅5360 = 2^3 \cdot 3^2 \cdot 5 has 4⋅3⋅2=244 \cdot 3 \cdot 2 = 24 divisors.

The sum of divisors works the same way, with the choices weighted by their values. For a single prime power, 1+p+⋯+pa=pa+1−1p−11 + p + \cdots + p^a = \frac{p^{a+1}-1}{p-1}. Because the choices for different primes multiply, the divisor sum factors too: σ(n)=∏i=1k(1+pi+pi2+⋯+piai).\sigma(n) = \prod_{i=1}^{k} \left(1 + p_i + p_i^2 + \cdots + p_i^{a_i}\right). So σ(360)=(1+2+4+8)(1+3+9)(1+5)=15⋅13⋅6=1170\sigma(360) = (1+2+4+8)(1+3+9)(1+5) = 15 \cdot 13 \cdot 6 = 1170. The reason multiplication works is that the map (e1,…,ek)↦p1e1⋯pkek(e_1,\ldots,e_k) \mapsto p_1^{e_1}\cdots p_k^{e_k} is a bijection between tuples and divisors, and the weight of a product is the product of the weights.

Restricted counts follow the same pattern. A divisor is a perfect square exactly when every exponent is even, so you count even choices for each prime. The sum of odd divisors of 360360 uses only the odd part 45=32⋅545 = 3^2 \cdot 5, giving σ(45)=13⋅6=78\sigma(45) = 13 \cdot 6 = 78. A number has an odd number of divisors exactly when it is a perfect square, because the divisors pair off as dd and n/dn/d unless d=n/dd = n/d.

Counting divisors of a factorial uses the exponent formula of Legendre. The exponent of pp in m!m! is ⌊m/p⌋+⌊m/p2⌋+⋯\lfloor m/p \rfloor + \lfloor m/p^2 \rfloor + \cdots, since each multiple of pjp^j contributes one more factor of pp. Once these exponents are known, the divisor count of m!m! is a product as above.

KEY FACTS
  • d(n)=(a1+1)⋯(ak+1)d(n) = (a_1+1)\cdots(a_k+1) when n=p1a1⋯pkakn = p_1^{a_1}\cdots p_k^{a_k}
  • σ(n)=∏i(1+pi+⋯+piai)\sigma(n) = \prod_i (1 + p_i + \cdots + p_i^{a_i}), a product over the prime powers
  • nn has an odd number of divisors exactly when nn is a perfect square
  • The exponent of pp in m!m! is ∑j≥1⌊m/pj⌋\sum_{j \ge 1} \lfloor m/p^j \rfloor

Spot it: The problem asks how many divisors a number has, how many divisors satisfy an extra condition, the sum of the divisors, or which numbers have a prescribed number of divisors.

COMMON MISTAKES
  • Adding exponents instead of adding 11 to each exponent before multiplying
  • Counting pairs (d,n/d)(d, n/d) and forgetting that a square root of nn is counted once
  • Using σ(n)\sigma(n) for a sum over prime divisors only, which ignores the higher powers
TRY IT

What is the sum of all positive divisors of 6060?

Practise this lesson (5 problems) →

5.Modular arithmetic and inverses

We write a≡b(modm)a \equiv b \pmod m when m∣(a−b)m \mid (a - b), equivalently when aa and bb leave the same remainder on division by mm. For example 29≡5(mod12)29 \equiv 5 \pmod{12} because 29−5=2429 - 5 = 24. Congruence is an equivalence relation, and it respects arithmetic: if a≡ba \equiv b and c≡d(modm)c \equiv d \pmod m, then a+c≡b+da + c \equiv b + d, a−c≡b−da - c \equiv b - d and ac≡bd(modm)ac \equiv bd \pmod m. The proof is one line: (a+c)−(b+d)=(a−b)+(c−d)(a+c) - (b+d) = (a-b) + (c-d) is a sum of multiples of mm.

This means you may replace any number in a computation by its remainder at any step. To compute 74 mod 107^4 \bmod 10, note 72=49≡97^2 = 49 \equiv 9, so 74≡92=81≡1(mod10)7^4 \equiv 9^2 = 81 \equiv 1 \pmod{10}. Reducing early keeps the numbers small and is the main technique behind almost every modular problem.

Division is different. Cancelling a common factor is allowed only when that factor is coprime to the modulus: if ac≡bc(modm)ac \equiv bc \pmod m and gcd⁡(c,m)=1\gcd(c,m) = 1, then a≡b(modm)a \equiv b \pmod m. The reason is that m∣c(a−b)m \mid c(a-b) and gcd⁡(c,m)=1\gcd(c,m) = 1 force m∣(a−b)m \mid (a-b).

An inverse of aa modulo mm is a number xx with ax≡1(modm)ax \equiv 1 \pmod m. It exists exactly when gcd⁡(a,m)=1\gcd(a,m) = 1. The Euclidean algorithm produces it: running the algorithm on aa and mm gives 1=ax+my1 = ax + my for integers x,yx, y, and reducing mod mm shows xx is the inverse. For example 3⋅5=15≡1(mod7)3 \cdot 5 = 15 \equiv 1 \pmod 7, so 3−1≡5(mod7)3^{-1} \equiv 5 \pmod 7. Inverses let you solve linear congruences ax≡b(modm)ax \equiv b \pmod m by multiplying both sides by a−1a^{-1}.

Beware of the nonexistent: 2x≡4(mod6)2x \equiv 4 \pmod 6 has solutions x≡2(mod3)x \equiv 2 \pmod 3 rather than a single residue, because gcd⁡(2,6)=2\gcd(2,6) = 2 does not divide into the modulus. Always check the gcd before cancelling.

KEY FACTS
  • a≡b(modm)a \equiv b \pmod m means m∣(a−b)m \mid (a-b), and congruences can be added and multiplied
  • ac≡bc(modm)ac \equiv bc \pmod m with gcd⁡(c,m)=1\gcd(c,m)=1 implies a≡b(modm)a \equiv b \pmod m
  • aa has an inverse modulo mm exactly when gcd⁡(a,m)=1\gcd(a,m) = 1
  • ax≡b(modm)ax \equiv b \pmod m has gcd⁡(a,m)\gcd(a,m) solutions modulo mm when gcd⁡(a,m)\gcd(a,m) divides bb

Spot it: The problem asks for a remainder of a large product or power, a remainder of a sum of huge terms, or any question that can be rephrased as solving a linear congruence.

COMMON MISTAKES
  • Cancelling a common factor cc from ac≡bcac \equiv bc when gcd⁡(c,m)≠1\gcd(c,m) \ne 1
  • Reducing a subtraction to a negative remainder and forgetting to add the modulus back
  • Assuming a linear congruence has a unique solution when the gcd of the coefficient and the modulus is larger than 11
TRY IT

Find the remainder when 17202517^{2025} is divided by 55.

Practise this lesson (4 problems) →

6.Fermat, Euler and multiplicative orders

Fermat's Little Theorem says that if pp is prime and p∤ap \nmid a, then ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p. A short proof: the numbers a,2a,…,(p−1)aa, 2a, \ldots, (p-1)a are all nonzero mod pp and pairwise distinct, because ia≡jaia \equiv ja would force i≡ji \equiv j after cancelling aa. So they are a rearrangement of 1,2,…,p−11, 2, \ldots, p-1. Multiplying both sets together gives (p−1)!⋅ap−1≡(p−1)!(p-1)! \cdot a^{p-1} \equiv (p-1)!, and cancelling (p−1)!(p-1)! (which is coprime to pp) yields the theorem.

Euler's theorem generalises this. Let φ(m)\varphi(m) count the integers in {1,…,m}\{1, \ldots, m\} that are coprime to mm. If gcd⁡(a,m)=1\gcd(a,m) = 1 then aφ(m)≡1(modm)a^{\varphi(m)} \equiv 1 \pmod m. The same permutation argument works, since multiplication by aa permutes the reduced residues. For m=pkm = p^k we have φ(m)=pk−1(p−1)\varphi(m) = p^{k-1}(p-1), and for m=p1a1⋯prarm = p_1^{a_1}\cdots p_r^{a_r} the function is multiplicative: φ(m)=∏piai−1(pi−1)\varphi(m) = \prod p_i^{a_i - 1}(p_i - 1).

The practical use is exponent reduction. If gcd⁡(a,m)=1\gcd(a,m)=1, then aN mod ma^N \bmod m depends only on N mod φ(m)N \bmod \varphi(m). For example 3100 mod 113^{100} \bmod 11: since φ(11)=10\varphi(11) = 10 and 100≡0(mod10)100 \equiv 0 \pmod{10}, we get 3100≡13^{100} \equiv 1. Fermat is the case m=pm = p.

The multiplicative order of aa modulo mm is the least t>0t > 0 with at≡1(modm)a^t \equiv 1 \pmod m. The order always divides φ(m)\varphi(m), and aN≡1a^N \equiv 1 holds exactly when the order divides NN. Finding the order by testing divisors of φ(m)\varphi(m) is often faster than running through all powers.

Be careful with composite moduli: the relevant exponent is φ(m)\varphi(m), not m−1m-1, and Fermat's theorem does not apply unless the modulus is prime. A common trap is using p−1p-1 for p2p^2 instead of p(p−1)p(p-1).

KEY FACTS
  • Fermat: ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p when pp is prime and p∤ap \nmid a
  • Euler: aφ(m)≡1(modm)a^{\varphi(m)} \equiv 1 \pmod m when gcd⁡(a,m)=1\gcd(a,m) = 1
  • φ(pk)=pk−1(p−1)\varphi(p^k) = p^{k-1}(p-1), and φ\varphi is multiplicative
  • The multiplicative order of aa modulo mm divides φ(m)\varphi(m)

Spot it: The problem involves a huge exponent modulo a prime or a small composite number, or asks for a remainder that repeats with some period.

COMMON MISTAKES
  • Applying Fermat's theorem to a composite modulus, where the exponent should be φ(m)\varphi(m)
  • Reducing the exponent modulo pp rather than modulo p−1p-1
  • Forgetting the hypothesis gcd⁡(a,m)=1\gcd(a,m) = 1, which fails when aa shares a factor with mm
TRY IT

Find the remainder when 31003^{100} is divided by 1111.

Practise this lesson (3 problems) →

7.The Chinese Remainder Theorem

Suppose mm and kk are coprime and we want an integer nn with n≡a(modm)n \equiv a \pmod m and n≡b(modk)n \equiv b \pmod k. The Chinese Remainder Theorem says such an nn exists, and is unique modulo mkmk. The existence proof is a clean counting argument. Consider the mkmk integers 0,1,…,mk−10, 1, \ldots, mk - 1. If two of them, xx and yy, had the same residues modulo mm and modulo kk, then m∣(x−y)m \mid (x - y) and k∣(x−y)k \mid (x - y). Since gcd⁡(m,k)=1\gcd(m,k) = 1, this forces mk∣(x−y)mk \mid (x - y), which is impossible for distinct numbers in the range. So the pairs of residues are all attained, and each pair occurs exactly once.

To solve a specific system, write n=a+mtn = a + m t and substitute into the second congruence: a+mt≡b(modk)a + mt \equiv b \pmod k, which is a linear congruence in tt. Because gcd⁡(m,k)=1\gcd(m,k) = 1, mm has an inverse mod kk, and tt is found by multiplying by m−1m^{-1}. This is the practical method and is fast for small moduli.

As an example, solve n≡1(mod4)n \equiv 1 \pmod 4 and n≡2(mod5)n \equiv 2 \pmod 5. Write n=1+4tn = 1 + 4t. Then 1+4t≡2(mod5)1 + 4t \equiv 2 \pmod 5, so 4t≡14t \equiv 1. Since 4⋅4=16≡1(mod5)4 \cdot 4 = 16 \equiv 1 \pmod 5, the inverse of 44 is 44, giving t≡4t \equiv 4 and n=17n = 17. The solutions are n≡17(mod20)n \equiv 17 \pmod{20}.

The theorem extends to any number of pairwise coprime moduli, and it is the reason modular problems with a composite modulus can be split into prime-power pieces. For example n≡2100(mod45)n \equiv 2^{100} \pmod{45} can be handled by finding the value mod 99 and mod 55 separately and combining. The same trick handles moduli like 1000=8⋅1251000 = 8 \cdot 125.

Watch the coprimality hypothesis: n≡1(mod4)n \equiv 1 \pmod 4 and n≡2(mod6)n \equiv 2 \pmod 6 are incompatible, because the two conditions disagree mod 22, so the theorem's conclusion is not automatic when the moduli share a factor.

KEY FACTS
  • If gcd⁡(m,k)=1\gcd(m,k) = 1, the system n≡a(modm)n \equiv a \pmod m, n≡b(modk)n \equiv b \pmod k has a unique solution mod mkmk
  • The solution is found by writing n=a+mtn = a + mt and solving mt≡b−a(modk)mt \equiv b - a \pmod k
  • CRT splits a modulus into prime powers, which are then handled one at a time

Spot it: The problem gives several remainders at once, asks for a number with prescribed remainders, or asks for a remainder modulo a composite number whose factors are coprime.

COMMON MISTAKES
  • Applying the method to moduli that share a factor, where the system can have no solution
  • Solving one congruence and forgetting to check the others
  • Quoting the solution as one residue when it is only unique modulo the product of the moduli
TRY IT

Find the smallest positive integer nn with n≡1(mod4)n \equiv 1 \pmod 4 and n≡2(mod5)n \equiv 2 \pmod 5.

Practise this lesson (2 problems) →

8.Last digits and cycles

The last digit of NN is N mod 10N \bmod 10, and the last two digits are N mod 100N \bmod 100. Both are modular questions, and the strategy is to reduce every factor and every exponent as you go. Since 10=2⋅510 = 2 \cdot 5, the last digit is determined by the residues mod 22 and mod 55, and the last two digits by the residues mod 44 and mod 2525, which is the Chinese Remainder Theorem in action.

Powers of a fixed base repeat. Take a=3a = 3 mod 1010: the powers 3,9,7,13, 9, 7, 1 repeat with period 44, so the last digit of 3N3^N depends only on N mod 4N \bmod 4. This period is the multiplicative order of 33 modulo 1010. The same reasoning gives the period of aNa^N modulo mm as the order of aa modulo mm, and the order divides φ(m)\varphi(m) whenever gcd⁡(a,m)=1\gcd(a,m) = 1.

For huge exponents, the procedure is always the same. Find the modulus mm, compute the order tt of the base (or any multiple of it, such as φ(m)\varphi(m)), reduce the exponent mod tt, and evaluate. For example, the last two digits of 320253^{2025}: the order of 33 mod 100100 divides 2020, and 2025≡5(mod20)2025 \equiv 5 \pmod{20}. So 32025≡35=243≡43(mod100)3^{2025} \equiv 3^5 = 243 \equiv 43 \pmod{100}.

Sums of powers can be handled term by term, and cancellation in the cycle does a lot of work. If all terms beyond a certain index are divisible by the modulus, they vanish. For instance 1!+2!+⋯+100!1! + 2! + \cdots + 100! is congruent mod 1010 to 1+2+6+24=331 + 2 + 6 + 24 = 33, since every factorial from 5!5! on is divisible by 1010. So the last digit is 33.

A nested exponent such as 7777^{7^7} needs the top exponent first. Compute the order of 77 mod 100100, which is 44, then reduce 777^7 modulo 44. Since 7≡−1(mod4)7 \equiv -1 \pmod 4, we have 77≡−1≡3(mod4)7^7 \equiv -1 \equiv 3 \pmod 4, so 777≡73=343≡43(mod100)7^{7^7} \equiv 7^3 = 343 \equiv 43 \pmod{100}.

KEY FACTS
  • The last kk digits of NN are N mod 10kN \bmod 10^k
  • The powers aN mod ma^N \bmod m are periodic in NN, with period dividing φ(m)\varphi(m) when gcd⁡(a,m)=1\gcd(a,m)=1
  • n!≡0(mod10)n! \equiv 0 \pmod{10} for every n≥5n \ge 5

Spot it: The problem asks for the last digit or last two digits of a large power, product or sum, or the exponent is itself a large expression.

COMMON MISTAKES
  • Reducing the base mod 1010 but reducing the exponent mod 1010 instead of the cycle length
  • Stopping at the cycle of the last digit, when the question asks for the last two digits and the cycle is longer
  • Forgetting that a factor divisible by the modulus kills all later terms of a sum
TRY IT

Find the last two digits of 320253^{2025}.

Practise this lesson (2 problems) →

9.Number bases

In base bb, a numeral dkdk−1⋯d1d0d_k d_{k-1} \cdots d_1 d_0 with 0≤di≤b−10 \le d_i \le b-1 stands for ∑idibi\sum_{i} d_i b^i. Each place is worth bb times the place to its right because a base-bb numeral groups items into bundles of bb, bundles of bundles, and so on. The subscript tells you the base: (1101)2=8+4+0+1=13(1101)_2 = 8 + 4 + 0 + 1 = 13, while the decimal numeral 11011101 is a different number entirely.

The conversion from decimal to base bb is an algorithm built on the division algorithm. Divide NN by bb to get a quotient qq and remainder r0r_0, so N=bq+r0N = bq + r_0 with 0≤r0≤b−10 \le r_0 \le b-1. Then r0r_0 is the last digit, and the other digits are the base-bb expansion of qq. Repeating and reading the remainders from the last to the first gives the answer. For 1313 in base 22: 13=2⋅6+113 = 2 \cdot 6 + 1, 6=2⋅3+06 = 2 \cdot 3 + 0, 3=2⋅1+13 = 2 \cdot 1 + 1, 1=2⋅0+11 = 2 \cdot 0 + 1, so 13=(1101)213 = (1101)_2.

The last digit of NN in base bb is N mod bN \bmod b, so base questions are modular arithmetic in disguise. A numeral with nn digits in base bb satisfies bn−1≤N≤bn−1b^{n-1} \le N \le b^n - 1, which is the fastest way to estimate how many digits a number has.

Digit counts and digit sums also change with base. Each digit of NN in base bb is found by repeated division, so the sum of the digits of NN in base bb is congruent to NN modulo b−1b - 1, exactly as the decimal digit sum is congruent mod 99. This gives a quick divisibility test in any base.

Problems often ask how a numeral looks in several bases at once, or when a numeral in one base is a number in another. Translate both sides into polynomials in the bases and compare. For example, (ab‾)7(\overline{ab})_{7} and (ba‾)9(\overline{ba})_{9} are equal when 7a+b=9b+a7a + b = 9b + a, which simplifies to 6a=8b6a = 8b, a linear equation with only a few solutions.

KEY FACTS
  • (dk⋯d1d0)b=∑idibi(d_k \cdots d_1 d_0)_b = \sum_i d_i b^i with 0≤di≤b−10 \le d_i \le b-1
  • The last digit of NN in base bb is N mod bN \bmod b
  • A numeral with nn digits in base bb lies between bn−1b^{n-1} and bn−1b^n - 1
  • The digit sum of NN in base bb is congruent to NN modulo b−1b-1

Spot it: The problem writes a numeral with a small base subscript, asks for digits in another base, or asks how many digits a number has in some base.

COMMON MISTAKES
  • Reading a numeral in base bb with the decimal place values
  • Using a digit equal to the base, which is never allowed in base bb
  • Forgetting that the subscript base itself must be larger than every digit that appears
TRY IT

Write (1234)5(1234)_5 in base 1010.

Practise this lesson (1 problem) →

10.Diophantine equations

A Diophantine equation asks for integer or positive-integer solutions. On the AMC these are almost always polynomial equations that factor after a small rearrangement, and the solution is a finite list that you count. The first move is to look for a factorisation. Expressions such as xy−3x−3yxy - 3x - 3y become (x−3)(y−3)−9(x-3)(y-3) - 9 after adding 99 to both sides, and x2−y2=(x−y)(x+y)x^2 - y^2 = (x-y)(x+y) is a product that can be enumerated.

The method known as Simon's Favourite Factoring Trick applies to any equation of the form xy+ax+by=cxy + ax + by = c. Add abab to both sides to get (x+b)(y+a)=c+ab(x+b)(y+a) = c + ab. Then the integer solutions correspond to factor pairs of c+abc + ab, and you check each pair for the sign and size constraints. The same idea works for the reciprocal equation 1x+1y=1n\frac{1}{x} + \frac{1}{y} = \frac{1}{n}, which becomes (x−n)(y−n)=n2(x-n)(y-n) = n^2 after clearing denominators.

Sign and size constraints matter. If x,yx, y are positive, then x−nx - n and y−ny - n can both be negative only when xx and yy are both less than nn, and this is often impossible because the product of two integers in a short range is too small. So you usually only need the positive factor pairs, and you count those.

A difference of squares forces parity. The equation x2−y2=Nx^2 - y^2 = N requires x−yx - y and x+yx + y to have the same parity, so NN must be odd or a multiple of 44. Once the parity works, each factor pair (d,e)(d,e) with de=Nde = N and d<ed < e gives exactly one positive solution, since x=(d+e)/2x = (d+e)/2 and y=(e−d)/2y = (e-d)/2.

Modular arguments can rule out whole families. A sum of two squares is never congruent to 3(mod4)3 \pmod 4, and in general one checks the equation modulo a small number to reduce the search. Combine this with the factorisation and bounding steps, and the solution count follows.

KEY FACTS
  • x2−y2=(x−y)(x+y)x^2 - y^2 = (x-y)(x+y), and the two factors must have the same parity
  • xy+ax+by=cxy + ax + by = c becomes (x+b)(y+a)=c+ab(x+b)(y+a) = c + ab after adding abab to both sides
  • 1x+1y=1n\frac{1}{x} + \frac{1}{y} = \frac{1}{n} becomes (x−n)(y−n)=n2(x-n)(y-n) = n^2
  • A sum of two squares is never congruent to 3(mod4)3 \pmod 4

Spot it: The problem asks for the number of integer or positive-integer solutions of a polynomial equation, especially one with a product term or a reciprocal sum.

COMMON MISTAKES
  • Forgetting that a factor pair with both factors negative can give solutions with negative variables, which the problem may exclude
  • Counting ordered pairs when the problem asks for unordered ones, or the reverse
  • Missing the case where a factor pair has d=ed = e, which gives a single solution rather than two
TRY IT

Find the number of ordered pairs of positive integers (x,y)(x, y) with xy−3x−3y=0xy - 3x - 3y = 0.

Practise this lesson (3 problems) →

Separate divisibility information from size information.

Congruences describe residue classes, not unique integers. After solving a system, identify the common period and then impose a range or a smallest-positive condition. For exponent problems, find the cycle before reducing the exponent.

A theorem such as Fermat’s little theorem needs its hypotheses: the modulus must be prime and the base must be coprime to it. A shorter cycle may be visible directly, and using it can be faster than applying a larger general theorem.

Before you commit to a method

  • A residue calculation should end in a representative between zero and the modulus minus one.
  • Do not cancel a factor modulo mm unless it is invertible modulo mm, or handle the common divisor explicitly.
  • Check a CRT candidate in every original congruence.

Two problems to work through

Try the question on paper before opening its solution. For each step, explain why it follows from the previous one.

Use the short cycle

Find the remainder of 520265^{2026} when divided by 1313.

Show the full reasoning
  1. Notice 52=25≡−1(mod13)5^2=25\equiv-1\pmod{13}.
  2. Then 54≡15^4\equiv1, so powers repeat with a period dividing four.
  3. Because 2026=4(506)+22026=4(506)+2, the power is congruent to 525^2.
  4. The result is −1≡12(mod13)-1\equiv12\pmod{13}.

Answer: 12

Check or vary it: The next power has remainder 12⋅5≡8(mod13)12\cdot5\equiv8\pmod{13}. Consecutive powers provide a quick check on the cycle.

Build a CRT solution in stages

Find the least positive xx such that x≡2(mod5)x\equiv2\pmod5, x≡3(mod7)x\equiv3\pmod7, and x≡4(mod9)x\equiv4\pmod9.

Show the full reasoning
  1. Write x=5a+2x=5a+2. The condition modulo seven becomes 5a≡15a\equiv1, so a≡3(mod7)a\equiv3\pmod7.
  2. Hence a=7b+3a=7b+3 and x=35b+17x=35b+17.
  3. Modulo nine, this is 8b+8≡48b+8\equiv4, or 8b≡58b\equiv5. Since 8−1≡88^{-1}\equiv8, we get b≡4(mod9)b\equiv4\pmod9.
  4. Thus x=157+315cx=157+315c. The least positive value is 157157, which has the required three remainders.

Answer: 157

Check or vary it: The period is 5⋅7⋅9=3155\cdot7\cdot9=315 because the moduli are pairwise coprime. Every other solution differs by a multiple of 315315.

Make the method stick

Close the solutions and rewrite both arguments from memory. In the topic practice below, begin with an untimed warm-up, then work through the medium problems. If you miss one, write down the first step you could not justify before checking the solution. Retry it on another day without your notes.

Factor first, then count exponents

Before any casework, write the relevant numbers as products of prime powers. Divisor counts, gcds, lcms and square-divisor questions all become tables of exponents, and multiplication principle does the rest.

Reduce modulo small numbers early

When a huge number appears, reduce each factor modulo the small moduli that matter (usually 44, 99, 1010, 1111 or the prime in question) before multiplying. This keeps the arithmetic to a few digits and exposes periodic patterns.

Find the cycle, then shrink the exponent

For a power aNa^N modulo mm, compute the first few powers until the residues repeat, or use φ(m)\varphi(m). Reduce NN modulo that period and evaluate. For nested exponents, reduce the top exponent first.

Split the modulus with CRT

If a modulus factors into coprime pieces such as 8⋅1258 \cdot 125 or 9⋅59 \cdot 5, solve for the remainder modulo each piece and recombine. Each piece is a small problem, and the recombination is a short search.

Factor the equation and bound the factors

For a Diophantine equation, rearrange until it becomes a product equal to a constant, then enumerate the factor pairs. Use sign and size bounds to discard pairs that give negative or impossible values.

Check parity and residues before solving

Many equations have no solutions for a simple reason, such as a parity mismatch or a square that cannot be 33 modulo 44. A quick check modulo 22, 44 or 77 can eliminate whole families before any algebra.

Try each one first. “How do I start?” gives the way in; then reveal the solution one step at a time.

Example 1: Neither two nor five

Warm-up · #1–5

How many of the integers 1,2,…,1001, 2, \ldots, 100 are divisible by neither 22 nor 55?

  1. (A)30
  2. (B)40
  3. (C)50
  4. (D)60
  5. (E)70
How do I start?

Count the complement: numbers divisible by 22 or 55, then subtract from 100100.

Example 2: Squares plus one

Easy · #6–10

For how many integers nn with 1≤n≤1001 \le n \le 100 is n2+1n^2 + 1 divisible by 55?

  1. (A)20
  2. (B)40
  3. (C)50
  4. (D)60
  5. (E)80
How do I start?

Reduce the condition to a statement about nn modulo 55, then count residues.

Example 3: Cubes among divisors

Medium · #11–15

How many positive divisors of 666^6 are perfect cubes?

  1. (A)4
  2. (B)6
  3. (C)9
  4. (D)12
  5. (E)16
How do I start?

Write 66=26⋅366^6 = 2^6 \cdot 3^6 and treat the divisors as exponent pairs.

Example 4: Thousand-fold remainder

Hard · #16–20

What is the remainder when 210002^{1000} is divided by 10001000?

  1. (A)126
  2. (B)250
  3. (C)376
  4. (D)500
  5. (E)624
How do I start?

Split 1000=8⋅1251000 = 8 \cdot 125, handle the two pieces separately, then recombine.

Example 5: Difference of squares

Hard · #16–20

How many ordered pairs of positive integers (a,b)(a, b) satisfy a2−b2=2025a^2 - b^2 = 2025?

  1. (A)6
  2. (B)7
  3. (C)8
  4. (D)15
  5. (E)21
How do I start?

Factor the difference of squares and enumerate the factor pairs with the right parity.

Example 6: Divisor sum summed

Final five · #21–25

Find ∑k=1100⌊100k⌋\displaystyle\sum_{k=1}^{100} \left\lfloor \frac{100}{k} \right\rfloor.

  1. (A)400
  2. (B)441
  3. (C)482
  4. (D)500
  5. (E)520
How do I start?

Recognise the sum as the number of pairs (k,m)(k, m) with km≤100km \le 100, then count with the hyperbola symmetry.

Number Theory | Fermat's Little Theorem
Michael Penn
A clean statement and proof of Fermat's Little Theorem, the starting point for every exponent-reduction problem in this topic.
Number Theory | Corollaries to Fermat's Little Theorem
Michael Penn
Watch after the proof to see how Fermat's Little Theorem yields quick remainder computations and inverse facts.
Find the last two digits.
Michael Penn
A worked last-two-digits problem that uses Euler's generalisation of Fermat, useful for the cycles and exponent-reduction concept.
The Chinese Remainder Theorem (Number Theory 101)
CJ Nadance
A step-by-step solution of systems of congruences, the method used in the Chinese Remainder Theorem concept and its problems.

30 problems, easy to hard

6 × Warm-up · #1–56 × Easy · #6–108 × Medium · #11–156 × Hard · #16–204 × Final five · #21–25
30 problems
All 30 problemsWarm-up (#1–10)Medium (#11–15)Hard (#16–25)

Next topic: Counting & Combinatorics →