✓ Official Syllabus VerifiedStandards & Rigor ↗
🏆 Subsection I · Core International Olympiad Pillars (Chapters 1–8)
2

Number Theory I: Divisibility, Primes, Fermat–Euler Theorems & Chinese Remainder Theorem

🔢 Core Pillar 2 — Olympiad Number Theory I IMO · NSMO · KAUST KMC  ·  Euclidean algorithm & Bézout's identity  ·  Multiplicative functions τ(n), σ(n), φ(n)  ·  Fermat's Little, Euler's Totient & Wilson's Theorems  ·  Chinese Remainder Theorem (CRT)  ·  Legendre's formula & p-adic valuation v_p(n!)

Number theory is the signature battleground of Saudi NSMO, KAUST KMC, AIME, and the IMO. Mastering congruence arithmetic \pmod m, Euler’s totient theorem, the Chinese Remainder Theorem (CRT), and p-adic valuation \(v_p(n)\) converts enormous exponential expressions and divisibility claims into crisp, finite modular deductions.

● Definition 2.1 — Prime Factorization, Arithmetic Functions & p-adic Valuation

By the Fundamental Theorem of Arithmetic, every integer \( n > 1 \) factors uniquely as \( n = p_1^{e_1} p_2^{e_2} \cdots p_k^{e_k} \). Its key multiplicative invariants are:

\[ \tau(n) = \prod_{i=1}^k (e_i + 1), \qquad \sigma(n) = \prod_{i=1}^k \frac{p_i^{e_i+1} - 1}{p_i - 1}, \qquad \varphi(n) = n \prod_{i=1}^k \left(1 - \frac{1}{p_i}\right). \]

For a prime \( p \), the \( p \)-adic valuation \( v_p(n) \) is the largest exponent \( e \) such that \( p^e \mid n \). Legendre's Theorem gives the exact prime power dividing \( n! \):

\[ v_p(n!) = \sum_{j=1}^{\infty} \left\lfloor \frac{n}{p^j} \right\rfloor = \frac{n - s_p(n)}{p - 1}, \]

where \( s_p(n) \) is the sum of the base-\( p \) digits of \( n \).

● Theorem 2.2 — Fermat's Little, Euler's Totient, Wilson's Theorem & CRT

1. Euler's & Fermat's Theorems: If \( \gcd(a, m) = 1 \), then \( a^{\varphi(m)} \equiv 1 \pmod m \). In particular, for prime \( p \nmid a \), \( a^{p-1} \equiv 1 \pmod p \).

2. Wilson's Theorem: An integer \( p > 1 \) is prime if and only if \( (p - 1)! \equiv -1 \pmod p \) (and \( (p - 2)! \equiv 1 \pmod p \)).

3. Chinese Remainder Theorem (CRT): If \( m_1, m_2, \dots, m_r \) are pairwise coprime (\( \gcd(m_i, m_j) = 1 \)), then the system \( x \equiv c_i \pmod{m_i} \) has a unique solution modulo \( M = m_1 m_2 \cdots m_r \).

◆ Proof — Bijective Residue Permutation Proof of Euler's Totient Theorem

Let \( R = \{r_1, r_2, \dots, r_{\varphi(m)}\} \) be a reduced residue system modulo \( m \) (all \( 1 \le r_i \le m \) with \( \gcd(r_i, m) = 1 \)). Since \( \gcd(a, m) = 1 \), multiplication by \( a \) is injective modulo \( m \): if \( ar_i \equiv ar_j \pmod m \), multiplying by \( a^{-1} \pmod m \) yields \( r_i \equiv r_j \pmod m \). Moreover \( \gcd(ar_i, m) = 1 \), so \( \{ar_1, \dots, ar_{\varphi(m)}\} \) is simply a permutation of \( R \) modulo \( m \)! Multiplying all elements together gives:

\[ (ar_1)(ar_2)\cdots(ar_{\varphi(m)}) \equiv r_1 r_2 \cdots r_{\varphi(m)} \pmod m \implies a^{\varphi(m)} \prod_{i=1}^{\varphi(m)} r_i \equiv \prod_{i=1}^{\varphi(m)} r_i \pmod m. \]

Since \( \gcd\!\left(\prod r_i, m\right) = 1 \), we cancel \( \prod r_i \) to obtain \( a^{\varphi(m)} \equiv 1 \pmod m \). \( \blacksquare \)

High-Speed Olympiad Modular & Valuation Reference Table
Property / ModulusKey Olympiad FactApplication
Squares \(\pmod 4, 8\)\(n^2 \equiv 0, 1 \pmod 4\); odd \(n^2 \equiv 1 \pmod 8\)Ruling out sum-of-squares Diophantine solutions
Cubes \(\pmod 7, 9\)\(n^3 \equiv 0, \pm 1 \pmod 7\) and \(n^3 \equiv 0, \pm 1 \pmod 9\)Cubic Diophantine equations like \(x^3+y^3+z^3 = 9k \pm 4\)
Lifting the Exponent (LTE)Odd prime \(p \mid x-y,\; p \nmid xy \Rightarrow v_p(x^n - y^n) = v_p(x - y) + v_p(n)\)Exact power of \(p\) dividing \(a^n \pm b^n\) in NSMO/IMO
Multiplicative Order \(\operatorname{ord}_m(a)\)\(a^k \equiv 1 \pmod m \iff \operatorname{ord}_m(a) \mid k\); in particular \(\operatorname{ord}_m(a) \mid \varphi(m)\)Prime divisors of \(2^p - 1\) satisfy \(q \equiv 1 \pmod p\)
Bézout's Identity
\(\exists x,y \in \mathbb{Z}: ax + by = \gcd(a,b)\); modular inverse exists iff \(\gcd(a,m)=1\)
Divisor Product Identity
Product of all positive divisors of \(n\) is \(n^{\tau(n)/2}\)
Euclidean Polynomial Trick
\(\gcd(n^2+1, n+1) = \gcd((-1)^2+1, n+1) = \gcd(2, n+1)\)
Trailing Zeros of \(n!\)
Since \(v_2(n!) \ge v_5(n!)\), trailing zeros equal \(v_5(n!) = \sum_{k \ge 1} \lfloor n/5^k \rfloor\)
Chinese Remainder Theorem intersection on the integer line: numbers \(\equiv 2 \pmod 5\) (\(2, 7, 12, 17, 22, 27, 32\)) meet numbers \(\equiv 3 \pmod 7\) (\(3, 10, 17, 24, 31\)) uniquely modulo \(35\) at \(x \equiv 17 \pmod{35}\).
⊙ Explorer · Euclidean GCD Tiling, Bézout Inverse & Euler Totient Lab
interactive
\(\gcd(a, b)\) & \(\operatorname{lcm}(a, b)\)gcd = 6, lcm = 126
Bézout \(ax + by = d\)42(1) + 18(−2) = 6
Totient \(\varphi(a)\) & \(\tau(a)\)φ(42)=12, τ(42)=8

Slide \(a\) and \(b\) to watch Euclidean square-tiling peel off quotients until the final square side equals \(\gcd(a, b)\). Whenever \(\gcd(a, b) = 1\), the Bézout coefficient \(x \bmod b\) gives the modular inverse \(a^{-1} \pmod b\)!

Primitive-root star polygon modulo \(7\): powers of \(3 \pmod 7\) cycle through all \(\varphi(7) = 6\) nonzero residues \(3 \to 2 \to 6 \to 4 \to 5 \to 1\), illustrating multiplicative order \(\operatorname{ord}_7(3) = 6\).
Worked Example 2.A — Last Two Digits of a Power Tower via CRT + Euler (NSMO / KAUST)
Problem. Find the last two decimal digits of \( 7^{2026} \) (i.e., compute \( 7^{2026} \bmod 100 \)).
▸ Show step-by-step solution

Since \( 100 = 4 \times 25 \) with \( \gcd(4, 25) = 1 \), split modulo \( 4 \) and modulo \( 25 \) (or use \( \varphi(100) = 40 \)):
1. Modulo \( 4 \): \( 7 \equiv -1 \pmod 4 \implies 7^{2026} \equiv (-1)^{2026} = 1 \pmod 4 \).
2. Modulo \( 25 \): \( \varphi(25) = 25(1 - \frac{1}{5}) = 20 \), or even faster notice \( 7^2 = 49 \equiv -1 \pmod{25} \)! Thus \( 7^4 \equiv 1 \pmod{25} \) (multiplicative order \( 4 \) modulo \( 100 \)!).
3. Write \( 2026 = 4(506) + 2 \):
\[ 7^{2026} = (7^4)^{506} \cdot 7^2 \equiv 1^{506} \cdot 49 = 49 \pmod{100} \]
(checking \( 49 \equiv 1 \pmod 4 \) and \( 49 \equiv -1 \pmod{25} \) — both match!). Hence the last two digits are \( 49 \).

Worked Example 2.B — Wilson's Theorem Factorial Remainder (Olympiad Classic)
Problem. Find the remainder when \( 97! \) is divided by \( 101 \).
▸ Show step-by-step solution

Since \( 101 \) is prime, Wilson's Theorem gives \( 100! \equiv -1 \pmod{101} \). Expand the top three factors modulo \( 101 \):
\[ 100! = 100 \cdot 99 \cdot 98 \cdot 97! \equiv (-1)(-2)(-3) \cdot 97! = -6 \cdot 97! \pmod{101}. \]
Therefore \( -6 \cdot 97! \equiv -1 \pmod{101} \iff 6 \cdot 97! \equiv 1 \pmod{101} \).
To invert \( 6 \pmod{101} \), notice \( 101 + 1 = 102 = 6 \times 17 \), so \( 6 \times 17 = 102 \equiv 1 \pmod{101} \).
Multiplying both sides of \( 6 \cdot 97! \equiv 1 \pmod{101} \) by \( 17 \) gives \( 97! \equiv 17 \pmod{101} \).

Worked Example 2.C — Chinese Remainder Theorem Reconstruction (AIME / NSMO Stage 2)
Problem. Find the smallest positive integer \( N > 10 \) that leaves remainder \( 2 \) when divided by \( 5 \), remainder \( 4 \) when divided by \( 7 \), and remainder \( 6 \) when divided by \( 9 \).
▸ Show step-by-step solution

Look for a structural pattern in the remainders before brute-forcing CRT! At \( m = 5, 7, 9 \), the differences \( m - r \) are \( 5 - 2 = 3 \), \( 7 - 4 = 3 \), and \( 9 - 6 = 3 \) — every single remainder is 3 less than its modulus! That means:
\[ N \equiv -3 \pmod 5, \quad N \equiv -3 \pmod 7, \quad N \equiv -3 \pmod 9. \]
Since \( 5, 7, 9 \) are pairwise coprime with \( \operatorname{lcm}(5, 7, 9) = 315 \), CRT immediately gives \( N \equiv -3 \equiv 312 \pmod{315} \). Thus the smallest positive solution is \( N = 312 \).

Worked Example 2.D — Legendre's Valuation & Divisor Count (KAUST Finals / IMO Shortlist)
Problem. Find the largest integer \( k \) such that \( 12^k \) divides \( 60! \).
▸ Show step-by-step solution

Prime-factor the base first: \( 12 = 2^2 \cdot 3 \), so \( 12^k = 2^{2k} \cdot 3^k \). Thus \( 12^k \mid 60! \iff 2k \le v_2(60!) \) AND \( k \le v_3(60!) \), meaning \( k = \min\!\left(\left\lfloor \frac{v_2(60!)}{2} \right\rfloor,\; v_3(60!)\right) \).
1. Compute \( v_3(60!) \) by Legendre's formula:
\[ v_3(60!) = \left\lfloor \frac{60}{3} \right\rfloor + \left\lfloor \frac{60}{9} \right\rfloor + \left\lfloor \frac{60}{27} \right\rfloor = 20 + 6 + 2 = 28. \]
2. Compute \( v_2(60!) \):
\[ v_2(60!) = \left\lfloor \frac{60}{2} \right\rfloor + \left\lfloor \frac{60}{4} \right\rfloor + \left\lfloor \frac{60}{8} \right\rfloor + \left\lfloor \frac{60}{16} \right\rfloor + \left\lfloor \frac{60}{32} \right\rfloor = 30 + 15 + 7 + 3 + 1 = 56. \]
3. Compare constraints: \( \lfloor 56 / 2 \rfloor = 28 \) and \( v_3(60!) = 28 \)! Both bounds Tie at \( 28 \) — had you lazily assumed \( 3 \) is always the bottleneck without checking \( 2^2 \), you could miss cases like \( 8! \) (where \( v_3(8!) = 2 \) and \( \lfloor v_2(8!)/2 \rfloor = \lfloor 7/2 \rfloor = 3 \), vs \( 9! \) where \( v_3(9!) = 4 > \lfloor 7/2 \rfloor = 3 \)!). Here \( k = \min(28, 28) = 28 \).

⚠ Olympiad Trap — Never Reduce Exponents Modulo m Instead of φ(m)!

Exponents live modulo \( \varphi(m) \), NOT modulo \( m \)! Moreover, \( a^{\varphi(m)} \equiv 1 \pmod m \) requires \( \gcd(a, m) = 1 \). If \( \gcd(a, m) > 1 \) (for instance \( 6^{100} \bmod 40 \)), split \( 40 = 8 \times 5 \) into prime-power moduli via CRT: clearly \( 6^{100} \equiv 0 \pmod 8 \) (since \( 100 \ge 3 \)) and \( 6^{100} \equiv 1^{100} = 1 \pmod 5 \), yielding \( 6^{100} \equiv 16 \pmod{40} \) — NOT \( 1 \)!

▲ Contest Strategy — Euclidean Elimination on Variable Expressions

Whenever asked for the maximum possible value of \( \gcd(A(n), B(n)) \) as \( n \) varies over \( \mathbb{Z}^+ \) (e.g., \( \gcd(3n + 7, 5n + 2) \)), eliminate \( n \) linearly: \( d \mid 5(3n+7) - 3(5n+2) = 35 - 6 = 29 \). Thus \( d \in \{1, 29\} \), and checking \( 3n + 7 \equiv 0 \pmod{29} \implies n = 27 \) confirms \( 29 \) is achieved!

[Practice 2.1 · NSMO Stage 1 / Easy] How many positive integer divisors of \( 720 \) are perfect squares?
💡 Hint 1 of 3
Write the prime factorization \( 720 = 2^4 \cdot 3^2 \cdot 5^1 \).
💡 Hint 2 of 3
A divisor \( 2^a 3^b 5^c \) is a perfect square iff \( a, b, c \) are all even.
💡 Hint 3 of 3
Count valid choices: \( a \in \{0,2,4\} \), \( b \in \{0,2\} \), \( c \in \{0\} \).
Since \( 720 = 2^4 \cdot 3^2 \cdot 5^1 \), even exponents allow \( 3 \) choices for \( a \) (\(0,2,4\)), \( 2 \) choices for \( b \) (\(0,2\)), and \( 1 \) choice for \( c \) (\(0\)), giving \( 3 \times 2 \times 1 = 6 \) square divisors.
[Practice 2.2 · KAUST KMC / Easy] Compute Euler totient \( \varphi(360) \) — the number of integers \( 1 \le k \le 360 \) coprime to \( 360 \).
💡 Hint 1 of 3
Find the distinct prime factors of \( 360 = 2^3 \cdot 3^2 \cdot 5 \): primes \( 2, 3, 5 \).
💡 Hint 2 of 3
Apply \( \varphi(360) = 360\left(1 - \frac{1}{2}\right)\left(1 - \frac{1}{3}\right)\left(1 - \frac{1}{5}\right) \).
💡 Hint 3 of 3
Multiply \( 360 \times \frac{1}{2} \times \frac{2}{3} \times \frac{4}{5} \).
Using \( 360 = 2^3 \cdot 3^2 \cdot 5 \), we obtain \( \varphi(360) = 360 \cdot \frac{1}{2} \cdot \frac{2}{3} \cdot \frac{4}{5} = 96 \).
[Practice 2.3 · NSMO Stage 2 / Medium] Find the remainder when \( 3^{2026} \) is divided by \( 13 \).
💡 Hint 1 of 3
Test small powers of \( 3 \) modulo \( 13 \) before using \( \varphi(13) = 12 \)!
💡 Hint 2 of 3
Observe that \( 3^3 = 27 = 2(13) + 1 \equiv 1 \pmod{13} \)!
💡 Hint 3 of 3
Reduce the exponent \( 2026 \) modulo \( 3 \): sum of digits \( 2+0+2+6 = 10 \equiv 1 \pmod 3 \).
Since \( 3^3 \equiv 1 \pmod{13} \) and \( 2026 = 3(675) + 1 \), we have \( 3^{2026} = (3^3)^{675} \cdot 3^1 \equiv 1 \cdot 3 = 3 \pmod{13} \).
[Practice 2.4 · AIME / KAUST KMC / Hard] Find the unique integer \( x \in \{0, 1, \dots, 104\} \) satisfying \( x \equiv 1 \pmod 3 \), \( x \equiv 2 \pmod 5 \), and \( x \equiv 3 \pmod 7 \).
💡 Hint 1 of 3
Check the linear combination \( 2x + 1 \) against all three moduli \( 3, 5, 7 \)!
💡 Hint 2 of 3
Notice \( 2(1)+1 = 3 \equiv 0 \pmod 3 \), \( 2(2)+1 = 5 \equiv 0 \pmod 5 \), and \( 2(3)+1 = 7 \equiv 0 \pmod 7 \)!
💡 Hint 3 of 3
Thus \( 2x + 1 \equiv 0 \pmod{105} \implies 2x = 105 - 1 = 104 \).
In all three congruences, \( 2x + 1 \equiv 0 \pmod m \) for \( m \in \{3, 5, 7\} \). By CRT, \( 2x + 1 \equiv 0 \pmod{105} \). Taking \( 2x + 1 = 105 \) gives \( x = 52 \) (checking: \( 52 = 17(3)+1 = 10(5)+2 = 7(7)+3 \)).
[Practice 2.5 · NSMO National Finals / LTE] Using Lifting-the-Exponent (LTE), find the exact 3-adic valuation \( v_3(7^{54} - 1) \) — i.e., the largest integer \( k \) such that \( 3^k \mid (7^{54} - 1) \).
💡 Hint 1 of 3
Check LTE conditions for odd prime \( p = 3 \): \( x = 7, y = 1 \), so \( 3 \mid (7 - 1) = 6 \) and \( 3 \nmid 7 \cdot 1 \).
💡 Hint 2 of 3
Apply \( v_3(x^n - y^n) = v_3(x - y) + v_3(n) \) with \( x = 7, y = 1, n = 54 \).
💡 Hint 3 of 3
Compute \( v_3(6) = 1 \) and \( v_3(54) = v_3(2 \cdot 3^3) = 3 \).
Since \( p = 3 \) is an odd prime with \( 3 \mid (7 - 1) \) and \( 3 \nmid 7 \), LTE gives \( v_3(7^{54} - 1) = v_3(6) + v_3(54) = 1 + 3 = 4 \). Thus \( 3^4 = 81 \) is the highest power of \( 3 \) dividing \( 7^{54} - 1 \).

Number Theory I: Divisibility, Primes, Fermat–Euler Theorems & Chinese Remainder Theorem — Competition Proof Benchmark

6 pts No Calculator
For positive integer \(n\) and quadratic \(P(x) = x^2 + 3x + 10\) in Number Theory I: Divisibility, Primes, Fermat–Euler Theorems & Chinese Remainder Theorem, examine algebraic invariants below.
  1. (a)2 pts
    Express \(4P(x)\) as a square plus a positive constant.
    Scoring Guideline & Justification
    • [M1] Completes square on 4x^2 + 12x (1 pt)
    • [A1] Obtains (2x + 3)^2 + 31 (1 pt)
  2. (b)2 pts
    Deduce why \(P(n)\) has no real roots for any \(n\in\mathbb{R}\).
    Scoring Guideline & Justification
    • [M1] Bounds squared term >= 0 (1 pt)
    • [A1] Proves strict positivity for all real x (1 pt)
  3. (c)2 pts
    Find the remainder when \(P(10) - P(0)\) is divided by \(10\).
    Scoring Guideline & Justification
    • [M1] Computes 100 + 10k = 10(10 + k) (1 pt)
    • [A1] States remainder is 0 (1 pt)
Complete Worked Solution
(a) \(4P(x) = (2x+3)^2 + 31\). (b) Strictly positive discriminant check: \(4P(x) > 0\). (c) \(P(10)-P(0) = 10(10+3) \equiv 0 \pmod{10}\).
📝 Chapter Quiz