by, Subhajit Gorai
Date: 20/07/2026

A Treatise on Number Theory

Preface

Number theory begins with the simplest object in mathematics — the integer — and from it builds a subject of extraordinary depth. This treatise is written for a reader who already trusts their own logical machinery: someone preparing for JEE Advanced, the ISI/CMI entrance examinations (B.Stat, B.Math, M.Stat), INMO/IMO-level olympiad work, or the number-theoretic corners of competitive programming. Consequently we do not linger on motivation for its own sake; we state axioms, prove theorems in full wherever the proof teaches a reusable technique, and reserve extended commentary for the moments where a trick, once seen, becomes part of the reader's permanent toolkit.

Where a fully self-contained proof would require machinery well outside elementary number theory — the analytic apparatus behind the Prime Number Theorem, the structure theory of units in rings of integers behind Pell's equation, or the classical (if elementary) but lengthy lattice-point argument behind Quadratic Reciprocity — we say so explicitly, state the result precisely, name the method by which it is proved, and then use the result freely. A working mathematician relies on facts they have not personally re-derived; competition mathematics rewards the same discipline.

Each Part closes with one or two Challenge Problems: genuinely hard problems, worked in full, chosen because a single idea in that Part completely dissolves them. The aim is not merely to display a solution but to show the moment a technique becomes decisive.


Table of Contents

  • Preface
  • Conventions and Notation
  • Part I. Divisibility, Primes, and the Euclidean Algorithm
    • 1.1 The Division Algorithm
    • 1.2 Divisibility: Basic Properties
    • 1.3 GCD, LCM, and the Euclidean Algorithm
    • 1.4 Bézout's Identity and the Extended Euclidean Algorithm
    • 1.5 The Fundamental Theorem of Arithmetic
    • 1.6 The Distribution of Primes
    • 1.7 Challenge Problems
  • Part II. Modular Arithmetic and Classical Theorems
    • 2.1 Congruences and Residue Systems
    • 2.2 Linear Congruences
    • 2.3 The Chinese Remainder Theorem
    • 2.4 Fermat's Little Theorem and Euler's Theorem
    • 2.5 Wilson's Theorem
    • 2.6 Modular Exponentiation: Tricks and Traps
    • 2.7 Challenge Problems
  • Part III. Multiplicative Functions and Möbius Inversion
    • 3.1 Multiplicative Functions
    • 3.2 The Classical Functions: τ,σ,φ\tau, \sigma, \varphi
    • 3.3 Dirichlet Convolution
    • 3.4 The Möbius Function
    • 3.5 Möbius Inversion
    • 3.6 Challenge Problems
  • Part IV. Diophantine Equations
    • 4.1 Linear Diophantine Equations
    • 4.2 Pythagorean Triples
    • 4.3 Pell's Equation
    • 4.4 The Method of Infinite Descent
    • 4.5 Interlude: Gaussian Integers and Sums of Two Squares
    • 4.6 Challenge Problem
  • Part V. Advanced Tools: LTE, Primitive Roots, and Quadratic Residues
    • 5.1 The Lifting the Exponent Lemma
    • 5.2 Orders, Primitive Roots, and Indices
    • 5.3 Quadratic Residues and Euler's Criterion
    • 5.4 The Law of Quadratic Reciprocity
    • 5.5 Challenge Problems
  • Appendix A. Master Formula Sheet
  • Closing Remark: A Unifying Theme

Conventions and Notation

Throughout, unless otherwise stated, lowercase Latin letters a,b,c,d,m,n,ka,b,c,d,m,n,k denote integers, and p,qp,q denote primes.

SymbolMeaning
Z,N,Z+\mathbb{Z}, \mathbb{N}, \mathbb{Z}^+integers; non-negative integers; positive integers
aba \mid baa divides bb, i.e. b=akb = ak for some kZk \in \mathbb{Z}
aba \nmid baa does not divide bb
gcd(a,b)\gcd(a,b), lcm(a,b)\operatorname{lcm}(a,b)greatest common divisor, least common multiple
ab(modm)a \equiv b \pmod{m}m(ab)m \mid (a-b)
vp(n)v_p(n)the pp-adic valuation of nn: the exponent of pp in the prime factorization of nn
x,x\lfloor x \rfloor, \lceil x \rceilfloor and ceiling of a real number xx
φ(n)\varphi(n)Euler's totient function
τ(n)\tau(n) or d(n)d(n)number of positive divisors of nn
σ(n)\sigma(n)sum of positive divisors of nn
μ(n)\mu(n)the Möbius function
ω(n)\omega(n)number of distinct prime divisors of nn
Ω(n)\Omega(n)number of prime divisors of nn counted with multiplicity
(ap)\left(\dfrac{a}{p}\right)the Legendre symbol
ordm(a)\operatorname{ord}_m(a)the multiplicative order of aa modulo mm
[P][P]Iverson bracket: 11 if statement PP is true, 00 otherwise
fgf * gDirichlet convolution of arithmetic functions f,gf,g
ε(n)\varepsilon(n)the Dirichlet-convolution identity: ε(1)=1\varepsilon(1)=1, ε(n)=0\varepsilon(n) = 0 for n>1n>1
pn\prod_{p \mid n}, dn\sum_{d \mid n}product/sum over primes dividing nn / over positive divisors of nn
\blacksquareend of proof

We take for granted the Well-Ordering Principle (every non-empty subset of Z+\mathbb{Z}^+ has a least element) and the principle of mathematical induction (in fact these are logically equivalent, together with the Peano axioms, and we treat them as our starting axioms for Z\mathbb{Z}). All rings encountered are commutative with unity unless stated otherwise.


Part I — Divisibility, Primes, and the Euclidean Algorithm

1.1 The Division Algorithm

Theorem 1.1 (Division Algorithm). Let aZa \in \mathbb{Z} and bZ+b \in \mathbb{Z}^+. There exist unique integers qq (the quotient) and rr (the remainder) such that
a=bq+r,0r<b.a = bq + r, \qquad 0 \le r < b.

Proof. Existence. Consider the set S={abq:qZ}NS = \{a - bq : q \in \mathbb{Z}\} \cap \mathbb{N}. This set is non-empty: taking qq sufficiently negative (e.g. q=aq = -|a|) makes abqa-bq arbitrarily large and positive. By the Well-Ordering Principle, SS has a least element r=abq0r = a - bq_0 for some q0q_0. We claim r<br < b. If not, rbr \ge b, so rb=ab(q0+1)0r - b = a - b(q_0+1) \ge 0 is a smaller element of SS, contradicting minimality of rr. Hence 0r<b0 \le r < b.

Uniqueness. Suppose a=bq1+r1=bq2+r2a = bq_1+r_1 = bq_2+r_2 with 0r1,r2<b0 \le r_1,r_2 < b. Then b(q1q2)=r2r1b(q_1-q_2) = r_2 - r_1, so b(r2r1)b \mid (r_2-r_1). But r2r1<b|r_2-r_1| < b, so the only multiple of bb in this range is 00; hence r1=r2r_1=r_2 and consequently q1=q2q_1=q_2. \blacksquare

Remark. This single theorem is the seed of everything that follows: the Euclidean Algorithm, modular arithmetic, and unique factorization are all downstream consequences of the ability to divide with remainder.

1.2 Divisibility: Basic Properties

Definition. For integers a,ba,b, we say aba \mid b ("aa divides bb") if there exists kZk \in \mathbb{Z} with b=akb = ak.

Proposition 1.2. For integers a,b,c,x,ya,b,c,x,y:

  1. (Reflexivity) aaa \mid a.
  2. (Transitivity) If aba\mid b and bcb \mid c, then aca \mid c.
  3. (Linearity) If aba \mid b and aca \mid c, then a(bx+cy)a \mid (bx+cy) for all integers x,yx,y.
  4. If aba \mid b and b0b \neq 0, then ab|a| \le |b|.
  5. If aba\mid b and bab \mid a, then a=±ba = \pm b.

Proof. All are immediate from the definition. For (2): b=ak1,c=bk2c=ak1k2b=ak_1, c=bk_2 \Rightarrow c = ak_1k_2. For (3): b=ak1,c=ak2bx+cy=a(k1x+k2y)b=ak_1,c=ak_2 \Rightarrow bx+cy = a(k_1x+k_2y). For (4): if b=akb=ak with k0k\neq 0 then b=aka|b|=|a||k|\ge|a|. For (5): combine (4) both ways. \blacksquare

Trick. Property (3) — linearity — is the single most used divisibility fact in olympiad problem-solving. Whenever you know dd divides two quantities, you instantly know dd divides any integer linear combination of them. This is the seed from which Bézout's identity and the entire Euclidean algorithm grow.

1.3 GCD, LCM, and the Euclidean Algorithm

Definition. For integers a,ba,b, not both zero, gcd(a,b)\gcd(a,b) is the largest positive integer dividing both aa and bb. We set gcd(0,0)=0\gcd(0,0)=0 by convention. The least common multiple lcm(a,b)\operatorname{lcm}(a,b) is the smallest positive integer divisible by both aa and bb.

Theorem 1.3 (Euclidean Algorithm). For a,bZ+a,b \in \mathbb{Z}^+,
gcd(a,b)=gcd(b,amodb),\gcd(a,b) = \gcd(b, a \bmod b),
with gcd(a,0)=a\gcd(a,0) = a. Repeated application terminates and computes gcd(a,b)\gcd(a,b).

Proof. Write a=bq+ra = bq+r with 0r<b0\le r<b (Division Algorithm). Any common divisor dd of a,ba,b divides r=abqr = a-bq (linearity), so dd is a common divisor of b,rb,r; conversely any common divisor of b,rb,r divides a=bq+ra = bq+r, so is a common divisor of a,ba,b. Hence a,ba,b and b,rb,r have exactly the same set of common divisors, so in particular the same greatest one: gcd(a,b)=gcd(b,r)\gcd(a,b)=\gcd(b,r). Since remainders strictly decrease and are non-negative integers, the process terminates (Well-Ordering) at gcd(d,0)=d\gcd(d,0)=d. \blacksquare

Theorem 1.4. For positive integers a,ba,b: gcd(a,b)lcm(a,b)=ab\gcd(a,b)\cdot\operatorname{lcm}(a,b) = ab.

Proof. Let d=gcd(a,b)d = \gcd(a,b) and write a=daa=da', b=dbb=db' with gcd(a,b)=1\gcd(a',b')=1 (if a common factor g>1g>1 divided both a,ba',b', then dgdg would be a larger common divisor of a,ba,b than dd, contradiction). We claim lcm(a,b)=dab\operatorname{lcm}(a,b) = da'b'. Indeed dab=ab=abda'b' = ab' = a'b is a common multiple of a,ba,b. If MM is any common multiple, write M=at=datM = at = da't. Also bMdbdatbatb \mid M \Rightarrow db' \mid da't \Rightarrow b' \mid a't; since gcd(a,b)=1\gcd(a',b')=1, btb' \mid t, so tbt \ge b', giving MdabM \ge da'b'. Hence dabda'b' is the least common multiple. Therefore gcd(a,b)lcm(a,b)=ddab=(da)(db)=ab\gcd(a,b)\operatorname{lcm}(a,b) = d\cdot da'b' = (da')(db') = ab. \blacksquare

Remark (Complexity). The Euclidean Algorithm on inputs a>ba>b terminates in O(logb)O(\log b) steps. This is sharp: Lamé's Theorem shows the worst case occurs precisely on consecutive Fibonacci numbers Fn+1,FnF_{n+1}, F_n, since each step reduces the pair by the smallest possible factor.

1.4 Bézout's Identity and the Extended Euclidean Algorithm

Theorem 1.5 (Bézout's Identity). For integers a,ba,b not both zero, there exist integers x,yx,y such that
ax+by=gcd(a,b).ax+by = \gcd(a,b).
Moreover gcd(a,b)\gcd(a,b) is the smallest positive integer expressible as ax+byax+by.

Proof. Let S={ax+by:x,yZ}Z+S = \{ax+by : x,y\in\mathbb{Z}\}\cap \mathbb{Z}^+. Since a2+b2Sa^2+b^2 \in S (not both zero), SS\neq\varnothing, so by Well-Ordering it has a least element d=ax0+by0d=ax_0+by_0. We show d=gcd(a,b)d = \gcd(a,b).

(dad\mid a and dbd \mid b): By the Division Algorithm, a=dq+ra = dq+r, 0r<d0\le r<d. Then
r=adq=aq(ax0+by0)=a(1qx0)+b(qy0),r = a-dq = a - q(ax_0+by_0) = a(1-qx_0) + b(-qy_0),
so rr is itself of the form ax+byax+by. If r>0r>0, then rSr\in S and r<dr<d, contradicting minimality of dd. So r=0r=0, i.e. dad\mid a. Symmetrically dbd \mid b.

(Maximality): If cc is any common divisor of a,ba,b, then c(ax0+by0)=dc \mid (ax_0+by_0) = d by linearity, so cdc \le d. Hence dd is the greatest common divisor. \blacksquare

Corollary 1.6. gcd(a,b)=1\gcd(a,b)=1 if and only if there exist integers x,yx,y with ax+by=1ax+by=1.

The Extended Euclidean Algorithm. This is simply the Euclidean Algorithm run forward, then unwound by back-substitution to express gcd(a,b)\gcd(a,b) as an explicit combination ax+byax+by.

Worked Example 1.1. Compute gcd(240,46)\gcd(240,46) and find x,yx,y with 240x+46y=gcd(240,46)240x+46y=\gcd(240,46).

240=546+10,46=410+6,10=16+4,6=14+2,4=22+0.240 = 5\cdot 46 + 10,\quad 46 = 4\cdot 10 + 6,\quad 10 = 1\cdot 6+4,\quad 6=1\cdot4+2,\quad 4=2\cdot2+0.

So gcd(240,46)=2\gcd(240,46)=2. Back-substitute:
2=6142 = 6-1\cdot4
=61(1016)=2610= 6 - 1\cdot(10-1\cdot6) = 2\cdot6 - 10
=2(46410)10=246910= 2(46-4\cdot10) - 10 = 2\cdot46 - 9\cdot10
=2469(240546)=47469240.= 2\cdot46 - 9(240-5\cdot46) = 47\cdot46 - 9\cdot240.

Check: 4746=216247\cdot46 = 2162, 9240=21609\cdot240=2160, difference =2=2. So (x,y)=(9,47)(x,y)=(-9,47). \blacksquare

Application: Modular Inverses. If gcd(a,m)=1\gcd(a,m)=1, the extended Euclidean algorithm produces x,yx,y with ax+my=1ax+my=1, i.e. ax1(modm)ax\equiv 1\pmod m — so xx is the modular inverse a1modma^{-1}\bmod m. This runs in O(logm)O(\log m) time and, unlike Fermat-based inversion (Section 2.4), works for any modulus, prime or not, as long as gcd(a,m)=1\gcd(a,m)=1.

1.5 The Fundamental Theorem of Arithmetic

Lemma 1.7 (Euclid's Lemma). If pp is prime and pabp \mid ab, then pap\mid a or pbp \mid b.

Proof. Suppose pap \nmid a. Since the only positive divisors of pp are 11 and pp, and pap\nmid a, we get gcd(p,a)=1\gcd(p,a)=1. By Bézout, there exist x,yx,y with px+ay=1px+ay=1. Multiplying by bb:
pbx+aby=b.pbx + aby = b.
Now ppbxp \mid pbx trivially, and pabpabyp \mid ab \Rightarrow p \mid aby. So pp divides the left side, hence pbp \mid b. \blacksquare

Corollary 1.8. If prime pa1a2akp \mid a_1a_2\cdots a_k, then paip \mid a_i for some ii. (Immediate induction on kk.)

Theorem 1.9 (Fundamental Theorem of Arithmetic). Every integer n>1n>1 can be written as a product of primes, and this factorization is unique up to the order of the factors.

Proof. Existence, by strong induction on nn. If nn is prime, done. Otherwise n=abn=ab with 1<a,b<n1<a,b<n; by the inductive hypothesis aa and bb are each products of primes, hence so is nn.

Uniqueness. Suppose n=p1p2pr=q1q2qsn = p_1p_2\cdots p_r = q_1q_2\cdots q_s are two prime factorizations. Since p1q1qsp_1 \mid q_1\cdots q_s, Corollary 1.8 gives p1qjp_1 \mid q_j for some jj; as qjq_j is prime, p1=qjp_1=q_j. Cancel p1p_1 from both sides and induct on the (smaller) product n/p1n/p_1. By induction the remaining multisets of primes agree, so r=sr=s and the pip_i are a rearrangement of the qjq_j. \blacksquare

Theorem 1.10 (Euclid — Infinitude of Primes). There are infinitely many primes.

Proof. Suppose not: let p1,,pnp_1,\dots,p_n be all the primes. Let N=p1p2pn+1N = p_1p_2\cdots p_n + 1. Since N>1N>1, it has some prime factor pp (Theorem 1.9). But N1(modpi)N \equiv 1 \pmod{p_i} for every ii, so p{p1,,pn}p \notin \{p_1,\dots,p_n\} — a new prime, contradiction. \blacksquare

Trick. The Fundamental Theorem of Arithmetic converts multiplicative statements about integers into additive statements about exponent vectors n=piai(a1,a2,)n = \prod p_i^{a_i} \leftrightarrow (a_1,a_2,\dots). In particular:
gcd(a,b)=ppmin(vp(a),vp(b)),lcm(a,b)=ppmax(vp(a),vp(b)),\gcd(a,b) = \prod_p p^{\min(v_p(a),v_p(b))}, \qquad \operatorname{lcm}(a,b) = \prod_p p^{\max(v_p(a),v_p(b))},
which immediately re-proves Theorem 1.4, since min(x,y)+max(x,y)=x+y\min(x,y)+\max(x,y)=x+y for all reals x,yx,y.

1.6 The Distribution of Primes

Beyond mere infinitude, one asks: how dense are the primes? Let π(x)\pi(x) denote the number of primes x\le x.

Theorem 1.11 (Prime Number Theorem, statement only).
π(x)xlnxas x,\pi(x) \sim \frac{x}{\ln x} \quad \text{as } x \to \infty,
meaning limxπ(x)lnx/x=1\lim_{x\to\infty} \pi(x)\ln x / x = 1.

This was proved independently by Hadamard and de la Vallée Poussin in 1896, via the complex-analytic theory of the Riemann zeta function ζ(s)=ns\zeta(s) = \sum n^{-s} and the fact that ζ(s)0\zeta(s) \neq 0 on the line Re(s)=1\operatorname{Re}(s)=1. The proof requires complex analysis well beyond our scope here; we state the result and use it only for orientation.

Theorem 1.12 (Bertrand's Postulate). For every integer n>1n>1, there is a prime pp with n<p<2nn < p < 2n.

This has a genuinely elementary (if intricate) proof due to Erdős, using careful estimates on binomial coefficients (2nn)\binom{2n}{n}; we omit the details but note it is a frequently-cited existence tool in olympiad combinatorics–number-theory hybrids.

1.7 Challenge Problems

Challenge Problem 1.1. For integer a>1a>1 and positive integers m,nm,n, prove that
gcd(am1,an1)=agcd(m,n)1.\gcd(a^m-1,\, a^n-1) = a^{\gcd(m,n)}-1.

Solution. Let d=gcd(m,n)d=\gcd(m,n).

Step 1: ad1a^d-1 is a common divisor. Since dmd \mid m, write m=dkm=dk. Then am1=(ad)k1a^m - 1 = (a^d)^k - 1 is divisible by ad1a^d-1, using the factorization xk1=(x1)(xk1++1)x^k-1=(x-1)(x^{k-1}+\cdots+1) with x=adx=a^d. Similarly ad1an1a^d-1 \mid a^n-1.

Step 2: the "Euclidean algorithm" for exponents. Suppose m>nm > n and write m=qn+rm = qn+r (0r<n0\le r<n, Division Algorithm). Then
am1=aqn+r1=ar(aqn1)+(ar1).a^m - 1 = a^{qn+r}-1 = a^r(a^{qn}-1) + (a^r - 1).
Since an1aqn1a^n - 1 \mid a^{qn}-1 (by Step 1's argument applied to exponent qnqn, a multiple of nn), we get
am1ar1(modan1).a^m - 1 \equiv a^r - 1 \pmod{a^n-1}.
Hence gcd(am1,an1)=gcd(ar1,an1)=gcd(an1,ar1)\gcd(a^m-1, a^n-1) = \gcd(a^r-1, a^n-1) = \gcd(a^n-1,a^r-1).

Step 3: induction mirroring Theorem 1.3. The pair of exponents (m,n)(m,n) has stepped to (n,r)(n,r)exactly the update rule of the Euclidean Algorithm applied to m,nm,n themselves. Iterating, the sequence of exponent pairs terminates at (gcd(m,n),0)(\gcd(m,n),0) after finitely many steps, and correspondingly
gcd(am1,an1)==gcd(agcd(m,n)1,a01)=gcd(ad1,0)=ad1.\gcd(a^m-1,a^n-1) = \cdots = \gcd(a^{\gcd(m,n)}-1, a^0-1) = \gcd(a^{d}-1, 0) = a^d - 1.
\blacksquare

Remark. This is the prototype for a whole family of "exponential GCD" identities (e.g. for Fibonacci numbers, gcd(Fm,Fn)=Fgcd(m,n)\gcd(F_m,F_n)=F_{\gcd(m,n)}, provable by an entirely analogous descent).

Challenge Problem 1.2 (IMO 1959, Problem 1). Prove that the fraction 21n+414n+3\dfrac{21n+4}{14n+3} is irreducible for every natural number nn.

Solution. It suffices to show gcd(21n+4,14n+3)=1\gcd(21n+4,\,14n+3)=1. Consider
3(14n+3)2(21n+4)=42n+942n8=1.3(14n+3) - 2(21n+4) = 42n+9-42n-8 = 1.
This exhibits 11 as an integer combination of 21n+421n+4 and 14n+314n+3; by Corollary 1.6, gcd(21n+4,14n+3)=1\gcd(21n+4,14n+3)=1 for every integer nn. \blacksquare

Trick. This is the archetypal "GCD by inspection" move: to prove gcd(A,B)=1\gcd(A,B)=1, it is often faster to guess a small integer combination xA+yB=1xA+yB=1 than to run the full Euclidean algorithm.


Part II — Modular Arithmetic and Classical Theorems

2.1 Congruences and Residue Systems

Definition. For mZ+m \in \mathbb{Z}^+, ab(modm)a \equiv b \pmod m means m(ab)m \mid (a-b).

Proposition 2.1. Congruence modulo mm is an equivalence relation on Z\mathbb{Z}, and it is compatible with addition and multiplication:
ab, cd(modm)    a+cb+d,acbd(modm).a\equiv b, \ c\equiv d \pmod m \implies a+c\equiv b+d, \quad ac \equiv bd \pmod m.

Proof. Reflexivity, symmetry, transitivity are immediate from properties of divisibility. For compatibility: m(ab)m \mid (a-b) and m(cd)m\mid(c-d) give m(ab)+(cd)=(a+c)(b+d)m \mid (a-b)+(c-d) = (a+c)-(b+d). For products: acbd=acbc+bcbd=c(ab)+b(cd)ac-bd = ac-bc+bc-bd = c(a-b)+b(c-d), and mm divides both terms. \blacksquare

Definition. A complete residue system (CRS) modulo mm is a set of mm integers, pairwise incongruent mod mm (e.g. {0,1,,m1}\{0,1,\dots,m-1\}). A reduced residue system (RRS) modulo mm is a set of φ(m)\varphi(m) integers, each coprime to mm, pairwise incongruent mod mm (e.g. the integers in {1,,m}\{1,\dots,m\} coprime to mm).

Proposition 2.2. If {r1,,rm}\{r_1,\dots,r_m\} is a CRS mod mm and gcd(a,m)=1\gcd(a,m)=1, then {ar1,,arm}\{ar_1,\dots,ar_m\} is also a CRS mod mm; similarly a RRS maps to a RRS under multiplication by a unit. This is because xax(modm)x\mapsto ax \pmod m is a bijection on Z/mZ\mathbb{Z}/m\mathbb{Z} precisely when gcd(a,m)=1\gcd(a,m)=1 (it has inverse xa1xx \mapsto a^{-1}x).

2.2 Linear Congruences

Theorem 2.3. The congruence axb(modm)ax\equiv b\pmod m has a solution if and only if d=gcd(a,m)d=\gcd(a,m) divides bb. When solvable, it has exactly dd pairwise incongruent solutions modulo mm.

Proof. If axb(modm)ax\equiv b\pmod m has a solution, then m(axb)m \mid (ax-b), i.e. axmy=bax-my = b for some yy — a linear Diophantine equation, solvable in integers x,yx,y iff dbd\mid b (Section 4.1; equivalently, since da,md\mid a,m, we need dbd \mid b). Conversely if dbd \mid b, divide through: gcd(a/d,m/d)=1\gcd(a/d,\,m/d)=1, so a/da/d has an inverse mod m/dm/d (Corollary 1.6), giving a unique solution xx0(modm/d)x \equiv x_0 \pmod{m/d}. This single residue class mod m/dm/d splits into exactly dd residue classes mod mm:
xx0, x0+md, x0+2md, , x0+(d1)md(modm).x \equiv x_0,\ x_0+\tfrac{m}{d},\ x_0+2\tfrac{m}{d},\ \dots,\ x_0+(d-1)\tfrac{m}{d} \pmod m.
\blacksquare

2.3 The Chinese Remainder Theorem

Theorem 2.4 (CRT). Let m1,,mkm_1,\dots,m_k be pairwise coprime positive integers and M=m1m2mkM=m_1m_2\cdots m_k. For any integers a1,,aka_1,\dots,a_k, the system
xai(modmi),i=1,,kx\equiv a_i \pmod{m_i}, \quad i=1,\dots,k
has a solution xx, unique modulo MM.

Proof (constructive). For each ii, let Mi=M/miM_i = M/m_i. Since m1,,mkm_1,\dots,m_k are pairwise coprime, gcd(Mi,mi)=1\gcd(M_i,m_i)=1, so by the Extended Euclidean Algorithm there is yiy_i with Miyi1(modmi)M_iy_i \equiv 1\pmod{m_i}. Define
x0=i=1kaiMiyi.x_0 = \sum_{i=1}^k a_i M_i y_i.
Verification: fix jj. For iji\neq j, mjMim_j \mid M_i (since MiM_i contains mjm_j as a factor), so the ii-th term vanishes mod mjm_j. The jj-th term gives ajMjyjaj1=aj(modmj)a_jM_jy_j \equiv a_j \cdot 1 = a_j \pmod{m_j}. So x0aj(modmj)x_0 \equiv a_j\pmod{m_j} for every jj — existence.

Uniqueness mod MM: if x,xx,x' both solve the system, then mi(xx)m_i \mid (x-x') for every ii; since the mim_i are pairwise coprime, their product MM divides xxx-x' (an easy induction using Euclid's Lemma repeatedly), so xx(modM)x\equiv x' \pmod M. \blacksquare

Worked Example 2.1. Solve x2(mod3), x3(mod5), x2(mod7)x\equiv2\pmod3,\ x\equiv3\pmod5,\ x\equiv2\pmod7.

Here M=105M=105. M1=352(mod3)M_1=35\equiv2\pmod3, and 212(mod3)2^{-1}\equiv2\pmod3 (since 22=412\cdot2=4\equiv1), so y1=2y_1=2: term =2352=140=2\cdot35\cdot2=140.
M2=211(mod5)M_2=21\equiv1\pmod5, y2=1y_2=1: term =3211=63=3\cdot21\cdot1=63.
M3=151(mod7)M_3=15\equiv1\pmod7, y3=1y_3=1: term =2151=30=2\cdot15\cdot1=30.

Sum =140+63+30=233233210=23(mod105)=140+63+30=233\equiv233-210=23\pmod{105}.

Check: 23=37+22(mod3)23=3\cdot7+2\equiv2\pmod3; 23=45+33(mod5)23=4\cdot5+3\equiv3\pmod5; 23=37+22(mod7)23=3\cdot7+2\equiv2\pmod7. \checkmark So x23(mod105)x\equiv23\pmod{105}. \blacksquare

2.4 Fermat's Little Theorem and Euler's Theorem

Theorem 2.5 (Fermat's Little Theorem). If pp is prime and pap\nmid a, then ap11(modp)a^{p-1}\equiv1\pmod p. Equivalently, apa(modp)a^p\equiv a\pmod p for every integer aa.

Proof. Consider the p1p-1 numbers a1,a2,,a(p1)(modp)a\cdot1, a\cdot2,\dots,a\cdot(p-1) \pmod p. Since gcd(a,p)=1\gcd(a,p)=1, multiplication by aa is a bijection on the nonzero residues mod pp (Proposition 2.2), so this list is simply a permutation of 1,2,,p1(modp)1,2,\dots,p-1 \pmod p. Multiplying all p1p-1 terms in each list:
ap1(p1)!(p1)!(modp).a^{p-1}\cdot(p-1)! \equiv (p-1)! \pmod p.
Since pp is prime and none of 1,,p11,\dots,p-1 is divisible by pp, gcd((p1)!,p)=1\gcd((p-1)!,p)=1; cancel (p1)!(p-1)! from both sides (multiply by its inverse) to get ap11(modp)a^{p-1}\equiv1\pmod p. \blacksquare

Theorem 2.6 (Euler's Theorem). If gcd(a,n)=1\gcd(a,n)=1, then aφ(n)1(modn)a^{\varphi(n)}\equiv1\pmod n.

Proof. Identical strategy, using a reduced residue system {r1,,rφ(n)}\{r_1,\dots,r_{\varphi(n)}\} instead of {1,,p1}\{1,\dots,p-1\}. Since gcd(a,n)=1\gcd(a,n)=1, multiplication by aa permutes this RRS (Proposition 2.2), so
aφ(n)iriiri(modn).a^{\varphi(n)}\prod_{i} r_i \equiv \prod_i r_i \pmod n.
Each rir_i is coprime to nn, so ri\prod r_i is coprime to nn and cancellable, yielding aφ(n)1(modn)a^{\varphi(n)}\equiv1\pmod n. \blacksquare

Remark. Fermat's Little Theorem is the special case n=pn=p (prime), since φ(p)=p1\varphi(p)=p-1.

2.5 Wilson's Theorem

Theorem 2.7 (Wilson's Theorem). For prime pp: (p1)!1(modp)(p-1)!\equiv-1\pmod p.

Proof. For p=2p=2: 1!=11(mod2)1!=1\equiv-1\pmod2. For p=3p=3: 2!=21(mod3)2!=2\equiv-1\pmod3. Now let p>3p>3. Every a{1,,p1}a\in\{1,\dots,p-1\} has a unique inverse a1a^{-1} in the same set (since gcd(a,p)=1\gcd(a,p)=1). We ask: when is aa its own inverse, i.e. a21(modp)a^2\equiv1\pmod p? This factors as (a1)(a+1)0(modp)(a-1)(a+1)\equiv0\pmod p, so (Euclid's Lemma) a1a\equiv1 or a1p1(modp)a\equiv-1\equiv p-1\pmod p. So among {2,3,,p2}\{2,3,\dots,p-2\}, every element is paired with a distinct partner whose product is 1(modp)1\pmod p — these p3p-3 elements split into p32\frac{p-3}{2} pairs, each multiplying to 11. Hence
(p1)!=1(p1)pairs(aa1)1(p1)11(modp).(p-1)! = 1\cdot(p-1)\cdot\prod_{\text{pairs}} (a\cdot a^{-1}) \equiv 1\cdot(p-1)\cdot1 \equiv -1\pmod p.
\blacksquare

Remark (Converse). If n>1n>1 is composite, then (n1)!0(modn)(n-1)!\equiv0\pmod n (for n>4n>4; check n=4n=4 separately: 3!=62(mod4)3!=6\equiv2\pmod4). Hence Wilson's theorem, together with its converse, gives a (computationally useless, but theoretically clean) primality characterization: nn is prime iff (n1)!1(modn)(n-1)!\equiv-1\pmod n.

2.6 Modular Exponentiation: Tricks and Traps

Trick (Fast/Binary Exponentiation). To compute aemodma^e \bmod m, write ee in binary and repeatedly square:
ae=i:biti(e)=1a2i(modm),a^e = \prod_{i:\,\text{bit}_i(e)=1} a^{2^i} \pmod m,
computable in O(loge)O(\log e) modular multiplications, each keeping intermediate values reduced mod mm.

Trick (Reducing huge exponents). If gcd(a,m)=1\gcd(a,m)=1, Euler's theorem lets us reduce the exponent modulo φ(m)\varphi(m):
aeaemodφ(m)(modm).a^e \equiv a^{e \bmod \varphi(m)} \pmod m.

Trap. This reduction is only valid when gcd(a,m)=1\gcd(a,m)=1. If gcd(a,m)>1\gcd(a,m)>1, na"ively reducing the exponent mod φ(m)\varphi(m) can give a wrong answer (e.g. 2φ(4)=22=40(mod4)2^{\varphi(4)} = 2^2=4\equiv0\pmod4, but 20=1≢02^0=1\not\equiv0). The correct general statement, useful for towers of exponents, is:

Lemma 2.8 (Generalized Euler / "lifting the exponent bound"). For any integers a,ma,m and elog2me \ge \log_2 m,
aeaφ(m)+(emodφ(m))(modm).a^e \equiv a^{\varphi(m) + (e \bmod \varphi(m))} \pmod m.

This holds regardless of gcd(a,m)\gcd(a,m), and is typically proved via the Chinese Remainder Theorem by splitting mm into prime-power factors and analyzing each factor separately (on each prime power pkmp^k \mid m, once the exponent exceeds kk, all higher powers of aa divisible by pp collapse predictably). We state it and use it freely.

Worked Example 2.2 (Tower exponentiation). Compute 777(mod100)7^{7^{7^{\cdots}}} \pmod{100} (a tower of height 3\ge 3).

Here φ(100)=40\varphi(100)=40. Since the exponent (itself a tower of 77's) vastly exceeds log21006.6\log_2 100 \approx 6.6, Lemma 2.8 lets us reduce: we need 77mod407^{7^{\cdots}} \bmod 40 (one level down). Now φ(40)=16\varphi(40)=16, and again the remaining tower exceeds log240\log_2 40, so reduce further: need 77mod167^{7^{\cdots}}\bmod16. Now φ(16)=8\varphi(16)=8; 71(mod8)7\equiv-1\pmod8, so 7odd17(mod8)7^{\text{odd}}\equiv-1\equiv7\pmod8 (the remaining tower height is odd), giving exponent 7(mod16)\equiv7\pmod{16} hence effectively 77mod167^7 \bmod 16: 72=491(mod16)7^2=49\equiv1\pmod{16}, so 77=76717=7(mod16)7^7=7^{6}\cdot7\equiv1\cdot7=7\pmod{16}. Climbing back up: 77mod407^{7}\bmod40: since 72=499, 74811(mod40)7^2=49\equiv9,\ 7^4\equiv81\equiv1\pmod{40}, so 77=74727197=6323(mod40)7^7=7^4\cdot7^2\cdot7\equiv1\cdot9\cdot7=63\equiv23\pmod{40}. Finally 723mod1007^{23}\bmod100: using repeated squaring, 72=49, 74=492=24011, 781, 7161(mod100)7^2=49,\ 7^4=49^2=2401\equiv1,\ 7^8\equiv1,\ 7^{16}\equiv1\pmod{100} (since 741(mod100)7^4\equiv1\pmod{100} — check: 2401=24100+12401 = 24\cdot100+1, yes). So 723=72073134343(mod100)7^{23}=7^{20}\cdot7^3 \equiv 1\cdot343\equiv43\pmod{100}. The tower converges to 43(mod100)\equiv43\pmod{100}. \blacksquare

2.7 Challenge Problems

Challenge Problem 2.1 (IMO 2005, Problem 4). Determine all positive integers relatively prime to every term of the infinite sequence
an=2n+3n+6n1,n1.a_n = 2^n+3^n+6^n-1, \qquad n\ge1.

Solution. We claim the answer is n=1n=1 only (i.e. only 11 is coprime to every term). We show every prime pp divides some term ana_n; this forces any integer >1>1 (having some prime factor pp) to share a factor with ana_n for that pp, leaving only 11.

  • p=2p=2: a1=2+3+61=10a_1 = 2+3+6-1=10, and 2102\mid10.
  • p=3p=3: a2=4+9+361=48a_2 = 4+9+36-1=48, and 3483\mid48.
  • p>3p>3: Take n=p2n=p-2. Since p2,3,6p\nmid2,3,6, Fermat's Little Theorem gives xp11(modp)x^{p-1}\equiv1\pmod p for x{2,3,6}x\in\{2,3,6\}, so xp2x1(modp)x^{p-2}\equiv x^{-1}\pmod p. Hence
    ap221+31+611(modp).a_{p-2} \equiv 2^{-1}+3^{-1}+6^{-1} - 1 \pmod p.
    Since 21+31+61=3+2+16=12^{-1}+3^{-1}+6^{-1} = \dfrac{3+2+1}{6} = 1 as a rational identity that persists mod pp (as p6p\nmid6, so 66 is invertible and the identity 6(21+31+61)3+2+1=6(modp)6\cdot(2^{-1}+3^{-1}+6^{-1}) \equiv 3+2+1=6 \pmod p forces 21+31+6112^{-1}+3^{-1}+6^{-1}\equiv1), we get
    ap211=0(modp).a_{p-2} \equiv 1 - 1 = 0\pmod p.

So every prime divides some ana_n, and the answer is n=1\boxed{n=1}. \blacksquare

Remark. This is a beautiful demonstration that Fermat's Little Theorem is not just about computing powers, but about inverting elements when the exponent is exactly p2p-2 — a trick worth memorizing: xp2x1(modp)x^{p-2}\equiv x^{-1}\pmod p.

Challenge Problem 2.2. Show that for a prime p1(mod4)p\equiv1\pmod4, the congruence x21(modp)x^2\equiv-1\pmod p has a solution, namely x=(p12)!x=\left(\dfrac{p-1}{2}\right)!.

Solution. Split (p1)!(p-1)! into two halves and pair kpkk \leftrightarrow p-k:
(p1)!=[k=1(p1)/2k][k=(p+1)/2p1k]=[(p12)!]j=1(p1)/2(pj),(p-1)! = \left[\prod_{k=1}^{(p-1)/2} k\right]\cdot\left[\prod_{k=(p+1)/2}^{p-1} k\right] = \left[\left(\tfrac{p-1}{2}\right)!\right]\cdot\prod_{j=1}^{(p-1)/2}(p-j),
relabeling the second product via k=pjk = p-j for j=1,,p12j=1,\dots,\frac{p-1}{2}. Since pjj(modp)p-j\equiv-j\pmod p,
j=1(p1)/2(pj)j=1(p1)/2(j)=(1)(p1)/2(p12)!(modp).\prod_{j=1}^{(p-1)/2}(p-j) \equiv \prod_{j=1}^{(p-1)/2}(-j) = (-1)^{(p-1)/2}\left(\tfrac{p-1}{2}\right)! \pmod p.
Therefore
(p1)!(1)(p1)/2[(p12)!]2(modp).(p-1)! \equiv (-1)^{(p-1)/2}\left[\left(\tfrac{p-1}{2}\right)!\right]^2 \pmod p.
By Wilson's Theorem, the left side is 1(modp)\equiv-1\pmod p. Since p1(mod4)p\equiv1\pmod4, p12\frac{p-1}{2} is even, so (1)(p1)/2=1(-1)^{(p-1)/2}=1, giving
[(p12)!]21(modp).\left[\left(\tfrac{p-1}{2}\right)!\right]^2 \equiv -1\pmod p.
So x=(p12)!x=\left(\frac{p-1}{2}\right)! satisfies x21(modp)x^2\equiv-1\pmod p. \blacksquare

Remark (forward reference). If instead p3(mod4)p\equiv3\pmod4, the same computation gives [(p12)!]21(modp)\left[\left(\tfrac{p-1}{2}\right)!\right]^2\equiv1\pmod p, and in fact x21(modp)x^2\equiv-1\pmod p has no solution at all: if it did, any solution xx would satisfy x41x^4\equiv1 but x21≢1x^2\equiv-1\not\equiv1, so xx has multiplicative order exactly 44; but every order divides p1p-1 (Section 5.2), and 4(p1)4\nmid(p-1) when p3(mod4)p\equiv3\pmod4 — contradiction. This dichotomy ("1-1 is a QR mod pp iff p1(mod4)p\equiv1\pmod4") will reappear as the first supplementary law of Quadratic Reciprocity in Part V, proved there more slickly via Euler's Criterion — and again in Part IV, where it determines exactly which primes are sums of two squares.


Part III — Multiplicative Functions and Möbius Inversion

3.1 Multiplicative Functions

Definition. An arithmetic function is any f:Z+Cf:\mathbb{Z}^+\to\mathbb{C}. We say ff is:

  • multiplicative if f(1)=1f(1)=1 and f(mn)=f(m)f(n)f(mn)=f(m)f(n) whenever gcd(m,n)=1\gcd(m,n)=1;
  • completely multiplicative if f(1)=1f(1)=1 and f(mn)=f(m)f(n)f(mn)=f(m)f(n) for all m,nm,n (no coprimality needed).

Proposition 3.1. A multiplicative function is completely determined by its values on prime powers: if n=piain=\prod p_i^{a_i}, then f(n)=f(piai)f(n)=\prod f(p_i^{a_i}).

Proof. Immediate induction using multiplicativity, since distinct prime powers piaip_i^{a_i} are pairwise coprime. \blacksquare

Examples.

  • id(n)=n\operatorname{id}(n)=n and 1(n)=1\mathbf{1}(n)=1 (the constant function) are completely multiplicative.
  • The Liouville function λ(n)=(1)Ω(n)\lambda(n)=(-1)^{\Omega(n)} is completely multiplicative.
  • φ,τ,σ,μ\varphi,\tau,\sigma,\mu (below) are multiplicative but not completely multiplicative — e.g. μ(p2)=0μ(p)2=1\mu(p^2)=0\neq\mu(p)^2=1.

3.2 The Classical Functions: τ,σ,φ\tau,\sigma,\varphi

Let n=p1a1p2a2pkakn=p_1^{a_1}p_2^{a_2}\cdots p_k^{a_k}.

Theorem 3.2.
τ(n)=i=1k(ai+1),σ(n)=i=1kpiai+11pi1,φ(n)=ni=1k(11pi).\tau(n) = \prod_{i=1}^k (a_i+1), \qquad \sigma(n) = \prod_{i=1}^k \frac{p_i^{a_i+1}-1}{p_i-1}, \qquad \varphi(n) = n\prod_{i=1}^k\left(1-\frac1{p_i}\right).

Proof. For τ\tau: since τ\tau is multiplicative (divisors of coprime numbers correspond bijectively to pairs of divisors, one of each factor), it suffices to compute τ(pa)\tau(p^a): the divisors of pap^a are 1,p,,pa1,p,\dots,p^a, giving a+1a+1 of them.

For σ\sigma: similarly multiplicative; σ(pa)=1+p++pa=pa+11p1\sigma(p^a) = 1+p+\cdots+p^a = \dfrac{p^{a+1}-1}{p-1} (geometric series).

For φ\varphi: multiplicative (proved via CRT in the exercises, or directly: the map Z/mnZZ/mZ×Z/nZ\mathbb{Z}/mn\mathbb{Z} \to \mathbb{Z}/m\mathbb{Z}\times\mathbb{Z}/n\mathbb{Z} for coprime m,nm,n is a ring isomorphism, restricting to a bijection between units, so φ(mn)=φ(m)φ(n)\varphi(mn)=\varphi(m)\varphi(n)). We compute φ(pa)\varphi(p^a): among 1,,pa1,\dots,p^a, exactly the multiples of pp (there are pa1p^{a-1} of them) fail to be coprime to pap^a, so φ(pa)=papa1=pa(11/p)\varphi(p^a) = p^a - p^{a-1} = p^a(1-1/p). Multiplying over prime power factors gives the stated product formula. \blacksquare

3.3 Dirichlet Convolution

Definition. For arithmetic functions f,gf,g, their Dirichlet convolution is
(fg)(n)=dnf(d)g(n/d).(f*g)(n) = \sum_{d\mid n} f(d)\,g(n/d).

Proposition 3.3. Dirichlet convolution is commutative and associative, with identity element
ε(n)={1n=10n>1,fε=f for all f.\varepsilon(n) = \begin{cases}1 & n=1\\0&n>1\end{cases}, \qquad f*\varepsilon = f \text{ for all } f.

Proof. Commutativity: reindex dn/dd\mapsto n/d in the sum. Associativity: both (fg)h(f*g)*h and f(gh)f*(g*h) evaluated at nn equal abc=nf(a)g(b)h(c)\sum_{abc=n} f(a)g(b)h(c), a symmetric triple sum. The identity property is immediate since the only divisor pair contributing when g=εg=\varepsilon is (d,n/d)=(n,1)(d,n/d)=(n,1). \blacksquare

Theorem 3.4. If f,gf,g are multiplicative, so is fgf*g.

Proof. Let h=fgh=f*g and gcd(m,n)=1\gcd(m,n)=1. Every divisor ee of mnmn factors uniquely as e=d1d2e=d_1d_2 with d1md_1\mid m, d2nd_2\mid n (and then gcd(d1,d2)=1\gcd(d_1,d_2)=1, gcd(m/d1,n/d2)=1\gcd(m/d_1,n/d_2)=1 too). Hence
h(mn)=d1md2nf(d1d2)g ⁣(md1nd2)=d1md2nf(d1)f(d2)g ⁣(md1)g ⁣(nd2)h(mn) = \sum_{d_1\mid m}\sum_{d_2\mid n} f(d_1d_2)\,g\!\left(\tfrac{m}{d_1}\cdot\tfrac{n}{d_2}\right) = \sum_{d_1\mid m}\sum_{d_2\mid n} f(d_1)f(d_2)\,g\!\left(\tfrac{m}{d_1}\right)g\!\left(\tfrac{n}{d_2}\right)
(using multiplicativity of f,gf,g on the coprime factors) =[d1mf(d1)g(m/d1)][d2nf(d2)g(n/d2)]=h(m)h(n)= \left[\sum_{d_1\mid m} f(d_1)g(m/d_1)\right]\left[\sum_{d_2\mid n}f(d_2)g(n/d_2)\right] = h(m)h(n). \blacksquare

Key identities. Since τ(n)=dn1\tau(n)=\sum_{d\mid n}1, σ(n)=dnd\sigma(n)=\sum_{d\mid n}d, we have
τ=11,σ=id1.\tau = \mathbf{1}*\mathbf{1}, \qquad \sigma = \operatorname{id}*\mathbf{1}.

Theorem 3.5. φ1=id\varphi * \mathbf{1} = \operatorname{id}, i.e. dnφ(d)=n\displaystyle\sum_{d\mid n}\varphi(d) = n.

Proof. Consider the nn fractions 1n,2n,,nn\frac1n,\frac2n,\dots,\frac{n}{n}. Reduce each to lowest terms kd\frac{k}{d}, where necessarily dnd\mid n. For a fixed divisor dnd\mid n, the fractions reducing to have denominator exactly dd correspond to numerators k{1,,d}k\in\{1,\dots,d\} with gcd(k,d)=1\gcd(k,d)=1 — there are φ(d)\varphi(d) of these. Since every one of the original nn fractions falls into exactly one such class,
dnφ(d)=n.\sum_{d\mid n}\varphi(d) = n. \qquad \blacksquare

Dirichlet inverses. Every ff with f(1)0f(1)\neq0 has a unique Dirichlet inverse f1f^{-1} satisfying ff1=εf*f^{-1}=\varepsilon, computable recursively:
f1(1)=1f(1),f1(n)=1f(1)dnd>1f(d)f1(n/d)(n>1).f^{-1}(1) = \frac{1}{f(1)}, \qquad f^{-1}(n) = \frac{-1}{f(1)}\sum_{\substack{d\mid n\\ d>1}} f(d)\,f^{-1}(n/d) \quad (n>1).
(Derived directly by demanding (ff1)(n)=0(f*f^{-1})(n) = 0 for n>1n>1 and isolating the d=1d=1 term.)

3.4 The Möbius Function

Definition. μ(1)=1\mu(1)=1; if nn is squarefree with kk distinct prime factors, μ(n)=(1)k\mu(n)=(-1)^k; if nn has a repeated prime factor, μ(n)=0\mu(n)=0.

Proposition 3.6. μ\mu is multiplicative (immediate from the definition, since squarefreeness and the prime-factor count both behave multiplicatively over coprime arguments).

Theorem 3.7 (Fundamental Möbius Identity).
dnμ(d)={1n=10n>1,i.e.μ1=ε.\sum_{d\mid n} \mu(d) = \begin{cases} 1 & n=1 \\ 0 & n>1\end{cases}, \qquad\text{i.e.}\qquad \mu * \mathbf{1} = \varepsilon.

Proof. The case n=1n=1 is trivial. For n>1n>1, the function g(n):=dnμ(d)=(μ1)(n)g(n) := \sum_{d\mid n}\mu(d) = (\mu*\mathbf 1)(n) is multiplicative by Theorem 3.4, so by Proposition 3.1 it suffices to check g(pa)=0g(p^a)=0 for every prime power pap^a, a1a\ge1:
g(pa)=μ(1)+μ(p)+μ(p2)++μ(pa)=1+(1)+0++0=0.g(p^a) = \mu(1)+\mu(p)+\mu(p^2)+\cdots+\mu(p^a) = 1 + (-1) + 0+\cdots+0 = 0.
Since n>1n>1 has at least one prime-power factor pap^a in its factorization, and gg is multiplicative with g(pa)=0g(p^a)=0 there, g(n)=0g(n)=0. \blacksquare

Corollary. μ\mu is the Dirichlet inverse of 1\mathbf 1.

3.5 Möbius Inversion

Theorem 3.8 (Möbius Inversion Formula). If g(n)=dnf(d)g(n) = \sum_{d\mid n} f(d) for all nn (i.e. g=f1g=f*\mathbf1), then
f(n)=dnμ(d)g(n/d)for all n.f(n) = \sum_{d\mid n} \mu(d)\,g(n/d) \qquad \text{for all } n.

Proof. Convolve both sides of g=f1g=f*\mathbf1 with μ\mu on the right:
gμ=(f1)μ=f(1μ)=fε=f,g*\mu = (f*\mathbf1)*\mu = f*(\mathbf1*\mu) = f*\varepsilon = f,
using associativity/commutativity of Dirichlet convolution (Proposition 3.3) and 1μ=ε\mathbf1*\mu=\varepsilon (Theorem 3.7). \blacksquare

Worked Example 3.1. Since id=φ1\operatorname{id}=\varphi*\mathbf1 (Theorem 3.5), Möbius inversion gives
φ(n)=dnμ(d)nd,\varphi(n) = \sum_{d\mid n}\mu(d)\cdot\frac{n}{d},
recovering Theorem 3.2's product formula upon expansion — a second, purely combinatorial derivation of φ\varphi.

Trick (a clean corollary). For all N1N\ge1,
d=1Nμ(d)Nd=1.\sum_{d=1}^{N}\mu(d)\left\lfloor\frac{N}{d}\right\rfloor = 1.
Indeed, d=1Nμ(d)N/d=d=1Nμ(d)mNdm1=m=1Ndmμ(d)=m=1Nε(m)=ε(1)=1\sum_{d=1}^N \mu(d)\lfloor N/d\rfloor = \sum_{d=1}^N \mu(d)\sum_{\substack{m\le N\\ d\mid m}} 1 = \sum_{m=1}^N \sum_{d\mid m}\mu(d) = \sum_{m=1}^N \varepsilon(m) = \varepsilon(1)=1, using Theorem 3.7. This identity underlies fast (O(N2/3)O(N^{2/3}) or better) computations of Mertens-function-type sums in competitive programming.

3.6 Challenge Problems

Challenge Problem 3.1. Evaluate in closed form:
S(n)=i=1nj=1ngcd(i,j).S(n) = \sum_{i=1}^n\sum_{j=1}^n \gcd(i,j).

Solution. The key is the identity id=φ1\operatorname{id}=\varphi*\mathbf1 from Theorem 3.5, applied to gcd(i,j)\gcd(i,j) itself: for any positive integer m=gcd(i,j)m=\gcd(i,j),
m=dmφ(d).m = \sum_{d\mid m} \varphi(d).
Hence
S(n)=i=1nj=1n dgcd(i,j)φ(d)=d=1nφ(d)#{(i,j):1i,jn, di, dj},S(n) = \sum_{i=1}^n\sum_{j=1}^n\ \sum_{d\mid\gcd(i,j)} \varphi(d) = \sum_{d=1}^n \varphi(d)\cdot\#\{(i,j): 1\le i,j\le n,\ d\mid i,\ d\mid j\},
having swapped the order of summation (for each dd, we count all pairs (i,j)(i,j) for which dd divides both, since such pairs are exactly those contributing a φ(d)\varphi(d) term). The count of multiples of dd in {1,,n}\{1,\dots,n\} is n/d\lfloor n/d\rfloor, so the count of valid pairs is n/d2\lfloor n/d\rfloor^2. Therefore:
S(n)=d=1nφ(d)nd2.\boxed{S(n) = \sum_{d=1}^n \varphi(d)\left\lfloor\frac{n}{d}\right\rfloor^2.}

Verification for n=2n=2: direct computation gives gcd(1,1)+gcd(1,2)+gcd(2,1)+gcd(2,2)=1+1+1+2=5\gcd(1,1)+\gcd(1,2)+\gcd(2,1)+\gcd(2,2)=1+1+1+2=5. The formula: φ(1)2/12+φ(2)2/22=14+11=5\varphi(1)\lfloor2/1\rfloor^2+\varphi(2)\lfloor2/2\rfloor^2 = 1\cdot4+1\cdot1=5. \checkmark \blacksquare

Remark. This closed form is the standard tool for computing such sums for large nn in O(n)O(\sqrt n) time in competitive programming, by grouping equal values of n/d\lfloor n/d\rfloor into O(n)O(\sqrt n) blocks (the "divisor block" or "n/d\lfloor n/d\rfloor has only O(n)O(\sqrt n) distinct values" trick) combined with a precomputed prefix sum of φ\varphi.

Challenge Problem 3.2. Prove that for every n1n\ge1,
nφ(n)=dnμ(d)2φ(d).\frac{n}{\varphi(n)} = \sum_{d\mid n} \frac{\mu(d)^2}{\varphi(d)}.

Solution. Both sides are multiplicative functions of nn (the left side because n/φ(n)=pnp/(p1)n/\varphi(n)=\prod_{p\mid n} p/(p-1) depends only on the set of distinct primes dividing nn, which is a multiplicative-type quantity across coprime factors; the right side is a sum over squarefree divisors — nonzero only when dd is squarefree, since μ(d)2=0\mu(d)^2=0 otherwise — and is a Dirichlet convolution μ2(1/φ)\mu^2 * (\mathbf1/\varphi)... more directly, it is multiplicative as a divisor-sum of the multiplicative function dμ(d)2/φ(d)d \mapsto \mu(d)^2/\varphi(d), by the same style of argument as Theorem 3.4 applied to functions valued in Q\mathbb{Q}). By Proposition 3.1 it suffices to check equality on prime powers pap^a, a1a\ge1.

Left side at pap^a: paφ(pa)=papapa1=pp1\dfrac{p^a}{\varphi(p^a)} = \dfrac{p^a}{p^a-p^{a-1}} = \dfrac{p}{p-1}.

Right side at pap^a: the squarefree divisors of pap^a are only 11 and pp (any p2dp^2\mid d makes μ(d)=0\mu(d)=0), so
dpaμ(d)2φ(d)=μ(1)2φ(1)+μ(p)2φ(p)=1+1p1=pp1.\sum_{d\mid p^a}\frac{\mu(d)^2}{\varphi(d)} = \frac{\mu(1)^2}{\varphi(1)} + \frac{\mu(p)^2}{\varphi(p)} = 1 + \frac{1}{p-1} = \frac{p}{p-1}.

The two sides agree on every prime power, hence (both being multiplicative) they agree for all nn. \blacksquare


Part IV — Diophantine Equations

4.1 Linear Diophantine Equations

Theorem 4.1. The equation ax+by=cax+by=c (in integers x,yx,y, with a,ba,b not both zero) has a solution if and only if gcd(a,b)c\gcd(a,b)\mid c. When solvable, writing d=gcd(a,b)d=\gcd(a,b) and (x0,y0)(x_0,y_0) for any one solution, the complete solution set is
x=x0+bdt,y=y0adt,tZ.x = x_0 + \frac{b}{d}t, \qquad y = y_0 - \frac{a}{d}t, \qquad t\in\mathbb{Z}.

Proof. Necessity: da,bd(ax+by)=cd\mid a,b \Rightarrow d \mid (ax+by)=c. Sufficiency: Bézout (Theorem 1.5) gives x1,y1x_1,y_1 with ax1+by1=dax_1+by_1=d; if dcd\mid c, write c=dkc=d k and scale: x0=kx1,y0=ky1x_0=kx_1,y_0=ky_1 solves ax+by=cax+by=c.

General solution: if (x,y)(x,y) is any other solution, subtracting gives a(xx0)=b(yy0)a(x-x_0)=-b(y-y_0), so ad(xx0)=bd(yy0)\frac{a}{d}(x-x_0) = -\frac{b}{d}(y-y_0). Since gcd(a/d,b/d)=1\gcd(a/d,b/d)=1, Euclid's Lemma gives bd(xx0)\frac{b}{d} \mid (x-x_0), say xx0=bdtx-x_0 = \frac{b}{d}t; substituting back gives yy0=adty-y_0=-\frac{a}{d}t. Conversely every such pair is easily checked to solve the equation. \blacksquare

4.2 Pythagorean Triples

Definition. A triple of positive integers (x,y,z)(x,y,z) with x2+y2=z2x^2+y^2=z^2 is a Pythagorean triple; it is primitive if gcd(x,y,z)=1\gcd(x,y,z)=1 (equivalently, x,y,zx,y,z are pairwise coprime).

Theorem 4.2. Every primitive Pythagorean triple with yy even is given by
x=m2n2,y=2mn,z=m2+n2x = m^2-n^2, \qquad y=2mn, \qquad z=m^2+n^2
for coprime integers m>n>0m>n>0 of opposite parity, and every such choice of m,nm,n yields a primitive triple.

Proof. (Necessity.) First, x,yx,y cannot both be even (else gcd(x,y,z)2\gcd(x,y,z)\ge2). They cannot both be odd either: odd squares are 1(mod4)\equiv1\pmod4, so x2+y22(mod4)x^2+y^2\equiv2\pmod4 would force z22(mod4)z^2\equiv2\pmod4, impossible since squares are 0,1(mod4)\equiv0,1\pmod4. So exactly one of x,yx,y is even; by hypothesis it's yy, and x,zx,z are both odd (since z2=x2+y2z^2=x^2+y^2 with xx odd, yy even forces zz odd).

Since z,xz,x are odd, zxz-x and z+xz+x are both even; write zx=2az-x=2a, z+x=2bz+x=2b. From y2=z2x2=(zx)(z+x)=4aby^2=z^2-x^2=(z-x)(z+x)=4ab, we get (y/2)2=ab(y/2)^2=ab. Any common divisor of a,ba,b divides both a+b=za+b=z and ba=xb-a=x, hence divides gcd(x,z)=1\gcd(x,z)=1 (primitivity), so gcd(a,b)=1\gcd(a,b)=1. Since abab is a perfect square and a,ba,b are coprime, unique factorization forces each of a,ba,b to be a perfect square individually: a=n2a=n^2, b=m2b=m^2 for positive integers m>nm>n (as b>ab>a since x=ba>0x=b-a>0). Then:
z=a+b=m2+n2,x=ba=m2n2,y=2ab=2mn.z=a+b=m^2+n^2, \qquad x=b-a=m^2-n^2, \qquad y=2\sqrt{ab}=2mn.
Since gcd(a,b)=1gcd(m,n)=1\gcd(a,b)=1 \Rightarrow \gcd(m,n)=1. And since x=m2n2x=m^2-n^2 is odd, m,nm,n must have opposite parity (same parity would make m2n2m^2-n^2 even).

(Sufficiency.) Direct substitution: (m2n2)2+(2mn)2=m42m2n2+n4+4m2n2=(m2+n2)2(m^2-n^2)^2+(2mn)^2 = m^4-2m^2n^2+n^4+4m^2n^2 = (m^2+n^2)^2. Primitivity: any common prime pp of x,y,zx,y,z would (since z±x{2m2,2n2}z\pm x \in \{2m^2,2n^2\} and z,xz,x odd, pp odd) divide both m2m^2 and n2n^2, contradicting gcd(m,n)=1\gcd(m,n)=1. \blacksquare

Worked Example 4.1. (m,n)=(2,1)(m,n)=(2,1): (x,y,z)=(3,4,5)(x,y,z)=(3,4,5). (m,n)=(3,2)(m,n)=(3,2): (x,y,z)=(5,12,13)(x,y,z)=(5,12,13). (m,n)=(4,1)(m,n)=(4,1): (15,8,17)(15,8,17).

4.3 Pell's Equation

Definition. For a non-square positive integer dd, Pell's equation is x2dy2=1x^2-dy^2=1, sought in positive integers x,yx,y.

Motivation (continued fractions). The continued fraction expansion of d\sqrt d is eventually periodic, say d=[a0;a1,a2,,a]\sqrt d = [a_0;\overline{a_1,a_2,\dots,a_\ell}]. Its convergents pk/qkp_k/q_k satisfy pk2dqk2=(1)k+1(something bounded)p_k^2-dq_k^2 = (-1)^{k+1}\cdot(\text{something bounded}), and in fact one always finds among the convergents a fundamental solution (x1,y1)(x_1,y_1) — the smallest positive solution. We state this existence result (a consequence of Dirichlet's Approximation Theorem and the periodicity of the continued fraction of a quadratic irrational) and use it freely, rather than re-deriving the theory of continued fractions here.

Theorem 4.3. Let (x1,y1)(x_1,y_1) be the fundamental solution of x2dy2=1x^2-dy^2=1. Then every positive-integer solution (xk,yk)(x_k,y_k) is given by
xk+ykd=(x1+y1d)k,k=1,2,3,x_k + y_k\sqrt d = (x_1+y_1\sqrt d)^k, \qquad k=1,2,3,\dots

Proof idea. Solutions to x2dy2=1x^2-dy^2=1 correspond exactly to elements α=x+yd\alpha=x+y\sqrt d of the ring Z[d]\mathbb{Z}[\sqrt d] of norm N(α):=ααˉ=x2dy2N(\alpha) := \alpha\bar\alpha = x^2-dy^2 equal to 11, i.e. to units of norm 11. The norm is multiplicative, N(αβ)=N(α)N(β)N(\alpha\beta)=N(\alpha)N(\beta), so products and powers of norm-11 elements again have norm 11 — this shows every power (x1+y1d)k(x_1+y_1\sqrt d)^k gives a solution. That these exhaust all positive solutions (i.e. that x1+y1dx_1+y_1\sqrt d generates the full group of norm-11 units greater than 11) is a consequence of the general structure theorem for units in real quadratic orders (a special case of Dirichlet's Unit Theorem); we cite this rather than re-derive it. \blacksquare

Worked Example 4.2 (d=2d=2). The fundamental solution of x22y2=1x^2-2y^2=1 is (x1,y1)=(3,2)(x_1,y_1)=(3,2) (check: 98=19-8=1). Since (3+22)2=17+122(3+2\sqrt2)^2 = 17+12\sqrt2, the next solution is (17,12)(17,12): 1722122=289288=117^2-2\cdot12^2=289-288=1. \checkmark Equivalently, one has the linear recurrence
xk+1=3xk+4yk,yk+1=2xk+3yk.x_{k+1}=3x_k+4y_k, \qquad y_{k+1}=2x_k+3y_k.

4.4 The Method of Infinite Descent

Example 4.1 (warm-up descent). The equation x2+y2=3z2x^2+y^2=3z^2 has no solution in positive integers.

Proof. Squares mod 33 are 00 or 11. If x2+y20(mod3)x^2+y^2\equiv0\pmod3, checking all combinations from {0,1}\{0,1\} shows this forces x2y20(mod3)x^2\equiv y^2\equiv0\pmod3, i.e. 3x3\mid x and 3y3\mid y. Write x=3x1,y=3y1x=3x_1,y=3y_1: then 9x12+9y12=3z23(x12+y12)=z23z23z9x_1^2+9y_1^2=3z^2 \Rightarrow 3(x_1^2+y_1^2)=z^2 \Rightarrow 3\mid z^2 \Rightarrow 3\mid z, say z=3z1z=3z_1. Substituting: 3(x12+y12)=9z12x12+y12=3z123(x_1^2+y_1^2)=9z_1^2 \Rightarrow x_1^2+y_1^2=3z_1^2 — the same equation, with strictly smaller positive integers (assuming (x,y,z)(x,y,z) was a minimal positive solution, e.g. minimizing zz). This contradicts minimality unless no positive solution exists at all. \blacksquare

Theorem 4.4 (Fermat). The equation x4+y4=z2x^4+y^4=z^2 has no solution in positive integers.

Proof. Suppose a solution exists; choose one with zz minimal. First, gcd(x,y)=1\gcd(x,y)=1: if a prime pp divided both, then p4z2p^4 \mid z^2, so p2zp^2\mid z, and (x/p)4+(y/p)4=(z/p2)2(x/p)^4+(y/p)^4=(z/p^2)^2 would be a smaller solution, contradicting minimality of zz.

So (x2,y2,z)(x^2,y^2,z) is a primitive Pythagorean triple: (x2)2+(y2)2=z2(x^2)^2+(y^2)^2=z^2, and gcd(x2,y2)=1\gcd(x^2,y^2)=1. WLOG (by symmetry of the equation in x,yx,y) y2y^2 is even. By Theorem 4.2,
x2=m2n2,y2=2mn,z=m2+n2,x^2 = m^2-n^2, \qquad y^2=2mn, \qquad z=m^2+n^2,
for coprime m>n>0m>n>0 of opposite parity.

From x2=m2n2x^2=m^2-n^2, i.e. x2+n2=m2x^2+n^2=m^2: this is another primitive Pythagorean triple (as gcd(m,n)=1\gcd(m,n)=1). Since xx is odd (it is the "odd leg" of the first triple, as established in Theorem 4.2's proof) and exactly one of x,nx,n must be even, nn is even. Apply Theorem 4.2 again:
x=p2q2,n=2pq,m=p2+q2,x = p^2-q^2, \qquad n=2pq, \qquad m=p^2+q^2,
for coprime p>q>0p>q>0 of opposite parity.

Now recall y2=2mn=2m(2pq)=4mpqy^2=2mn = 2m(2pq) = 4mpq, so (y/2)2=mpq(y/2)^2 = mpq. We check m,p,qm,p,q are pairwise coprime: gcd(p,q)=1\gcd(p,q)=1 by construction; and since m=p2+q2m=p^2+q^2, any common prime factor of mm and pp would (as p2q2p^2\equiv-q^2) divide q2q^2 too, contradicting gcd(p,q)=1\gcd(p,q)=1 — similarly for m,qm,q. Since mpqmpq is a perfect square and m,p,qm,p,q are pairwise coprime, unique factorization forces each to be a perfect square individually:
m=r2,p=s2,q=t2m=r^2, \qquad p=s^2, \qquad q=t^2
for positive integers r,s,tr,s,t. Substituting into m=p2+q2m=p^2+q^2:
r2=s4+t4.r^2 = s^4+t^4.

This is a new solution of the original equation X4+Y4=Z2X^4+Y^4=Z^2, with Z=rZ=r. We now check r<zr<z, completing the descent: since n1n\ge1, z=m2+n2>m2mz=m^2+n^2 > m^2 \ge m (as m1m\ge1), and since r2=mr^2=m, if r1r\ge1 then rr2=m<zr\le r^2=m<z. So r<zr<z — a strictly smaller solution, contradicting the minimality of zz. \blacksquare

Corollary 4.5 (Fermat's Last Theorem, exponent 4). x4+y4=z4x^4+y^4=z^4 has no solution in positive integers (since such a solution would give x4+y4=(z2)2x^4+y^4=(z^2)^2, contradicting Theorem 4.4).

4.5 Interlude: Gaussian Integers and Sums of Two Squares

The ring of Gaussian integers Z[i]={a+bi:a,bZ}\mathbb{Z}[i] = \{a+bi : a,b\in\mathbb{Z}\} carries a multiplicative norm N(a+bi)=a2+b2N(a+bi)=a^2+b^2. One shows (via an explicit division algorithm using nearest-lattice-point rounding) that Z[i]\mathbb{Z}[i] is a Euclidean domain, hence a UFD — we state this structural fact and name the method (norm-Euclidean division) rather than re-derive it.

Theorem 4.6 (Fermat, sum of two squares). An odd prime pp can be written as p=a2+b2p=a^2+b^2 (for integers a,ba,b) if and only if p1(mod4)p\equiv1\pmod4.

Proof sketch. (p3(mod4)p\equiv3\pmod4 is impossible.) Squares mod 44 are 0,10,1, so a2+b2(mod4){0,1,2}a^2+b^2\pmod4 \in\{0,1,2\}, never 33.

(p1(mod4)p\equiv1\pmod4 \Rightarrow possible.) By Challenge Problem 2.2, there exists xx with x21(modp)x^2\equiv-1\pmod p, i.e. px2+1=(x+i)(xi)p \mid x^2+1 = (x+i)(x-i) in Z[i]\mathbb{Z}[i]. If pp were prime in Z[i]\mathbb{Z}[i], it would (by the UFD property) divide x+ix+i or xix-i — but then pp would divide both the real and imaginary parts of x±ix\pm i, in particular p1p\mid1, absurd. So pp is not prime in Z[i]\mathbb{Z}[i]: it factors as p=ππˉp=\pi\bar\pi for some non-unit π=a+bi\pi=a+bi (a genuine factorization, since Z[i]\mathbb{Z}[i] is a UFD and pp is reducible). Taking norms: p2=N(p)=N(π)N(πˉ)=N(π)2p^2 = N(p) = N(\pi)N(\bar\pi) = N(\pi)^2, so N(π)=pN(\pi)=p, i.e.
p=a2+b2.p = a^2+b^2. \qquad \blacksquare

Remark. This is a striking instance of the treatise's recurring theme: the modular-arithmetic fact "1-1 is a QR mod pp" (Part II) becomes, via the arithmetic of Z[i]\mathbb{Z}[i], a statement about which primes split in a larger ring — a first glimpse of algebraic number theory, to which we return in the Closing Remark.

4.6 Challenge Problem

Challenge Problem 4.1. Find all integer solutions of y2+2=x3y^2+2=x^3.

Solution. We work in Z[2]={a+b2:a,bZ}\mathbb{Z}[\sqrt{-2}] = \{a+b\sqrt{-2} : a,b\in\mathbb{Z}\}, with norm N(a+b2)=a2+2b2N(a+b\sqrt{-2})=a^2+2b^2. As with Z[i]\mathbb{Z}[i], one shows via an explicit division algorithm that Z[2]\mathbb{Z}[\sqrt{-2}] is a Euclidean domain (hence a UFD) with respect to this norm; we state and use this fact, naming the method (norm-Euclidean division), without re-deriving it. The only units are ±1\pm1 (the only elements of norm 11).

Step 1: parity of yy. If yy were even, y2+22(mod4)y^2+2\equiv2\pmod4, but x3(mod4)x^3\pmod4 is always 0,1,0,1, or 33 (never 22, checking xx even or odd) — contradiction. So yy is odd, and hence x3=y2+2x^3=y^2+2 is odd, so xx is odd too.

Step 2: factor. y2+2=(y+2)(y2)=x3y^2+2 = (y+\sqrt{-2})(y-\sqrt{-2}) = x^3.

Step 3: the two factors are coprime. Suppose a non-unit π\pi divides both y+2y+\sqrt{-2} and y2y-\sqrt{-2}. Then π\pi divides their difference 22=(2)32\sqrt{-2} = -(\sqrt{-2})^3 (since (2)2=2(\sqrt{-2})^2=-2, so (2)3=22(\sqrt{-2})^3 = -2\sqrt{-2}). The prime 22 ramifies in this ring: 2=(2)22 = -(\sqrt{-2})^2, so the only prime (up to units) dividing 222\sqrt{-2} is 2\sqrt{-2} itself. Hence π\pi is an associate of 2\sqrt{-2}, meaning 2y+2\sqrt{-2} \mid y+\sqrt{-2}, which forces 2y\sqrt{-2}\mid y — impossible in Z\mathbb{Z} unless 2y2\mid y, contradicting Step 1 (yy odd). So the two factors are coprime.

Step 4: extract a cube. In a UFD, if a product of two coprime elements is a perfect cube, each factor is (up to a unit) itself a cube. Since the only units are ±1=(±1)3\pm1=(\pm1)^3, we may absorb any sign and write
y+2=(a+b2)3y+\sqrt{-2} = (a+b\sqrt{-2})^3
for some integers a,ba,b. Expanding, using (2)2=2, (2)3=22(\sqrt{-2})^2=-2,\ (\sqrt{-2})^3=-2\sqrt{-2}:
(a+b2)3=a3+3a2b2+3ab2(2)+b3(22)=(a36ab2)+(3a2b2b3)2.(a+b\sqrt{-2})^3 = a^3+3a^2b\sqrt{-2}+3ab^2(-2)+b^3(-2\sqrt{-2}) = (a^3-6ab^2) + (3a^2b-2b^3)\sqrt{-2}.
Matching real and 2\sqrt{-2}-coefficients:
y=a(a26b2),1=b(3a22b2).y = a(a^2-6b^2), \qquad 1 = b(3a^2-2b^2).

Step 5: solve the Diophantine constraint. Since b(3a22b2)=1b(3a^2-2b^2)=1 with a,bZa,b\in\mathbb{Z}, we need b=±1b=\pm1.

  • If b=1b=1: 3a22=1a2=1a=±13a^2-2=1 \Rightarrow a^2=1 \Rightarrow a=\pm1.
  • If b=1b=-1: (3a22)=13a2=1-(3a^2-2)=1 \Rightarrow 3a^2=1, no integer solution.

So b=1b=1, a=±1a=\pm1. Then y=a(a26)=a(16)=5a=5y=a(a^2-6)=a(1-6)=-5a = \mp5, i.e. y=±5y=\pm5, and
x3=y2+2=25+2=27    x=3.x^3 = y^2+2 = 25+2=27 \implies x=3.

Conclusion: the only integer solutions are (x,y)=(3,±5)(x,y)=(3,\pm5). \blacksquare

Remark. This is the classical showcase (due originally to Euler, made rigorous once unique factorization in Z[2]\mathbb{Z}[\sqrt{-2}] is established) of solving a Mordell-type equation y2+k=x3y^2+k=x^3 by factoring over a quadratic ring of algebraic integers — the direct generalization of the Gaussian-integer technique of Section 4.5, and the natural cousin of Fermat's infinite-descent method in Theorem 4.4: both replace an intractable equation over Z\mathbb{Z} with a tractable factorization in a larger UFD.


Part V — Advanced Tools: LTE, Primitive Roots, and Quadratic Residues

5.1 The Lifting the Exponent Lemma

Theorem 5.1 (LTE, odd prime case). Let pp be an odd prime and let x,yx,y be integers with pxp\nmid x, pyp\nmid y, and p(xy)p\mid(x-y). Then for every positive integer nn,
vp(xnyn)=vp(xy)+vp(n).v_p(x^n-y^n) = v_p(x-y) + v_p(n).

Proof. Step 1 (the case n=pn=p). Write a=vp(xy)1a=v_p(x-y)\ge1, so x=y+pamx=y+p^am with pmp\nmid m. Factor
xpyp=(xy)(xp1+xp2y++yp1)S.x^p-y^p = (x-y)\underbrace{(x^{p-1}+x^{p-2}y+\cdots+y^{p-1})}_{S}.
We must show vp(S)=1v_p(S)=1 exactly. Modulo pa+1p^{a+1}, using xy+pamx\equiv y+p^am:
xiyp1iyp1+iyp2pam(modpa+1)x^iy^{p-1-i} \equiv y^{p-1} + i\,y^{p-2}\,p^am \pmod{p^{a+1}}
(expanding xi=(y+pam)iyi+iyi1pam(modp2a)x^i = (y+p^am)^i \equiv y^i + iy^{i-1}p^am \pmod {p^{2a}}, and since a1a\ge1, certainly mod pa+1p^{a+1} too). Summing over i=0,,p1i=0,\dots,p-1:
Spyp1+pamyp2p(p1)2(modpa+1).S \equiv p\,y^{p-1} + p^am\,y^{p-2}\cdot\frac{p(p-1)}{2} \pmod{p^{a+1}}.
Since pp is odd, p(p1)2=pp12\frac{p(p-1)}{2} = p\cdot\frac{p-1}{2} is itself a multiple of pp, so the second term is a multiple of pa+1p^{a+1} and vanishes mod pa+1p^{a+1}. Hence Spyp1(modpa+1)S\equiv p\,y^{p-1}\pmod{p^{a+1}}; since pyp\nmid y, vp(pyp1)=1v_p(py^{p-1})=1, and as a+12>1a+1\ge2>1, this pins down vp(S)=1v_p(S)=1 exactly. Therefore vp(xpyp)=a+1=vp(xy)+1v_p(x^p-y^p) = a+1 = v_p(x-y)+1, confirming the theorem for n=pn=p.

Step 2 (pnp\nmid n). If pnp\nmid n, factor xnyn=(xy)(xn1++yn1)x^n-y^n=(x-y)(x^{n-1}+\cdots+y^{n-1}); the second factor is nyn1(modp)\equiv n\,y^{n-1}\pmod p (since xyx\equiv y), and pnyn1p\nmid ny^{n-1}, so this factor contributes vp=0v_p=0. Hence vp(xnyn)=vp(xy)v_p(x^n-y^n)=v_p(x-y) whenever pnp\nmid n.

Step 3 (general nn). Write n=pbnn=p^bn' with pnp\nmid n'. By Step 2, vp(xnyn)=vp(xy)v_p(x^{n'}-y^{n'})=v_p(x-y), and xnyn(modp)x^{n'}\equiv y^{n'}\pmod p still holds (in fact mod pap^a). Applying Step 1 exactly bb times to the pair (xn,yn)(x^{n'},y^{n'}), each application raising the valuation by exactly 11:
vp(xpbnypbn)=vp(xnyn)+b=vp(xy)+vp(n).v_p(x^{p^bn'}-y^{p^bn'}) = v_p(x^{n'}-y^{n'}) + b = v_p(x-y) + v_p(n). \qquad \blacksquare

Corollary 5.2 (odd-power sum case). If additionally p(x+y)p\mid(x+y) (with px,yp\nmid x,y), then for every odd positive integer nn,
vp(xn+yn)=vp(x+y)+vp(n).v_p(x^n+y^n) = v_p(x+y)+v_p(n).

(Apply Theorem 5.1 to xx and y-y: px(y)=x+yp\mid x-(-y)=x+y, and (y)n=yn(-y)^n=-y^n for odd nn, so xn(y)n=xn+ynx^n-(-y)^n=x^n+y^n.)

Theorem 5.3 (LTE, p=2p=2 case — statement). Let x,yx,y be odd integers.

  • If nn is odd: v2(xnyn)=v2(xy)v_2(x^n-y^n)=v_2(x-y).
  • If nn is even: v2(xnyn)=v2(xy)+v2(x+y)+v2(n)1v_2(x^n-y^n) = v_2(x-y)+v_2(x+y)+v_2(n)-1.

The proof follows the same binomial-expansion strategy as Theorem 5.1 but requires extra casework specific to the prime 22 (since, e.g., xyx-y and x+yx+y are both even when x,yx,y are odd, unlike the odd-prime case where only one factor need be divisible by pp). We state the result and use it freely.

Worked Example 5.1. Find v3(2100+1)v_3(2^{100}+1). Since 21(mod3)2\equiv-1\pmod3, we have 3(2+1)3\mid(2+1); and 100100 is even so we cannot directly apply the odd-sum corollary (which needs nn odd). Instead write 2100+12^{100}+1... actually since 100100 is even, use xnynx^n-y^n form: note 210011002^{100}-1^{100} doesn't involve +1+1. Let's instead compute v3(21001)v_3(2^{100}-1): since 3(21)=13\mid(2-1)=1? No — 313\nmid1. Reconsider: apply LTE with x=4,y=1x=4,y=1 (since 2100=4502^{100}=4^{50}): 3(41)=33\mid(4-1)=3. So v3(450150)=v3(3)+v3(50)=1+0=1v_3(4^{50}-1^{50}) = v_3(3)+v_3(50) = 1+0=1. But we want 2100+12^{100}+1, not 210012^{100}-1. Since 221(mod3)2^2\equiv1\pmod3 (order 22), and 100100 is even, 21001(mod3)2^{100}\equiv1\pmod3, so 2100+12(mod3)2^{100}+1\equiv2\pmod3, i.e. 3(2100+1)3\nmid(2^{100}+1) at all — v3(2100+1)=0v_3(2^{100}+1)=0. This example is a useful caution: always check the hypotheses of LTE (px±yp\mid x\pm y) before applying it — here they simply fail, and direct modular reasoning settles the question immediately.

5.2 Orders, Primitive Roots, and Indices

Definition. For gcd(a,n)=1\gcd(a,n)=1, the order of aa modulo nn, written ordn(a)\operatorname{ord}_n(a), is the smallest positive integer kk with ak1(modn)a^k\equiv1\pmod n.

Proposition 5.4. ordn(a)φ(n)\operatorname{ord}_n(a) \mid \varphi(n), and more generally ordn(a)e\operatorname{ord}_n(a) \mid e for any ee with ae1(modn)a^e\equiv1\pmod n.

Proof. Let d=ordn(a)d=\operatorname{ord}_n(a) and suppose ae1a^e\equiv1. By the Division Algorithm, e=dq+re=dq+r, 0r<d0\le r<d. Then 1ae=(ad)qarar(modn)1\equiv a^e = (a^d)^qa^r\equiv a^r\pmod n. If r>0r>0, this contradicts minimality of dd; so r=0r=0, i.e. ded\mid e. Taking e=φ(n)e=\varphi(n) (valid by Euler's Theorem) gives dφ(n)d\mid\varphi(n). \blacksquare

Definition. gg is a primitive root modulo nn if ordn(g)=φ(n)\operatorname{ord}_n(g)=\varphi(n), i.e. the powers of gg generate every residue coprime to nn.

Theorem 5.5 (Existence of primitive roots mod a prime). For every prime pp, a primitive root modulo pp exists.

Proof. For each divisor d(p1)d\mid(p-1), let ψ(d)\psi(d) be the number of elements of {1,,p1}\{1,\dots,p-1\} with order exactly dd. We show ψ(d){0,φ(d)}\psi(d)\in\{0,\varphi(d)\} for each dd, and dp1ψ(d)=p1\sum_{d\mid p-1}\psi(d)=p-1; since also dp1φ(d)=p1\sum_{d\mid p-1}\varphi(d)=p-1 (Theorem 3.5), equality ψ(d)=φ(d)\psi(d)=\varphi(d) for every dd is forced — in particular ψ(p1)=φ(p1)1\psi(p-1)=\varphi(p-1)\ge1, so a primitive root exists.

Why ψ(d){0,φ(d)}\psi(d)\in\{0,\varphi(d)\}: Suppose ψ(d)>0\psi(d)>0, i.e. some aa has order exactly dd. Then a,a2,,ada,a^2,\dots,a^d are dd distinct solutions (mod pp) of xd1(modp)x^d\equiv1\pmod p — and a polynomial of degree dd has at most dd roots over the field Z/pZ\mathbb{Z}/p\mathbb{Z} (a standard fact: if xd1x^d-1 had more than dd roots, polynomial division by (xr)(x-r) for each root would eventually force the zero polynomial to have positive degree, a contradiction — valid since Z/pZ\mathbb{Z}/p\mathbb{Z} is an integral domain, having no zero divisors, so (xr)(x-r) divides out cleanly at each root). So {a,a2,,ad}\{a,a^2,\dots,a^d\} is the complete solution set of xd1x^d\equiv1, and every element of order dd must be among these powers aka^k; a direct check shows aka^k has order exactly dd iff gcd(k,d)=1\gcd(k,d)=1, of which there are φ(d)\varphi(d) values. So ψ(d)=φ(d)\psi(d)=\varphi(d) whenever it is positive, confirming ψ(d){0,φ(d)}\psi(d)\in\{0,\varphi(d)\}.

Finally dp1ψ(d)=p1\sum_{d\mid p-1}\psi(d)=p-1 since every one of 1,,p11,\dots,p-1 has some order dividing p1p-1 (Proposition 5.4). \blacksquare

Theorem 5.6 (Existence, general case — statement). A primitive root modulo nn exists if and only if
n{1,2,4, pk, 2pk}for an odd prime p and k1.n \in \{1,2,4,\ p^k,\ 2p^k\} \quad \text{for an odd prime } p \text{ and } k\ge1.

The forward extension (from prime pp to prime power pkp^k) is proved by an explicit lifting argument: if gg is a primitive root mod pp, then either gg or g+pg+p is a primitive root mod p2p^2, and once one has a primitive root mod p2p^2 it automatically remains one mod pkp^k for all kk (a computation using the Binomial Theorem, in the same spirit as the LTE proof above). The obstruction for 2k2^k, k3k\ge3: the group (Z/2kZ)×(\mathbb{Z}/2^k\mathbb{Z})^\times is not cyclic for k3k\ge3 but splits as Z/2×Z/2k2\mathbb{Z}/2\times\mathbb{Z}/2^{k-2} (a classical structure theorem of Gauss). We state these without full proof.

Indices (discrete logarithm). If gg is a primitive root mod nn, every aa coprime to nn is agind(a)(modn)a\equiv g^{\operatorname{ind}(a)}\pmod n for a unique ind(a){0,,φ(n)1}\operatorname{ind}(a)\in\{0,\dots,\varphi(n)-1\}, and ind(ab)ind(a)+ind(b)(modφ(n))\operatorname{ind}(ab)\equiv\operatorname{ind}(a)+\operatorname{ind}(b)\pmod{\varphi(n)} — indices behave exactly like logarithms, converting multiplicative congruence problems into additive (linear congruence) ones.

5.3 Quadratic Residues and Euler's Criterion

Definition. For odd prime pp and pap\nmid a, aa is a quadratic residue (QR) mod pp if x2a(modp)x^2\equiv a\pmod p has a solution, and a non-residue (NQR) otherwise. The Legendre symbol is
(ap)={1a is a QR mod p1a is a NQR mod p0pa.\left(\frac ap\right) = \begin{cases}1 & a \text{ is a QR mod } p\\ -1 & a \text{ is a NQR mod } p\\ 0 & p\mid a.\end{cases}

Theorem 5.7 (Euler's Criterion). For pap\nmid a,
a(p1)/2(ap)(modp).a^{(p-1)/2} \equiv \left(\frac ap\right) \pmod p.

Proof. Let gg be a primitive root mod pp (Theorem 5.5), and write agk(modp)a\equiv g^k\pmod p. The quadratic residues are exactly the even powers of gg (since g2j=(gj)2g^{2j}=(g^j)^2 is manifestly a square, and these p12\frac{p-1}{2} distinct even powers must be all the QRs, as xx2x\mapsto x^2 is exactly 22-to-11 on the p1p-1 nonzero residues). So aa is a QR iff kk is even.

Now, a(p1)/2=gk(p1)/2a^{(p-1)/2} = g^{k(p-1)/2}. If kk is even, k(p1)/2k(p-1)/2 is a multiple of p1p-1, so gk(p1)/21(modp)g^{k(p-1)/2}\equiv1\pmod p. If kk is odd, note g(p1)/2g^{(p-1)/2} has order exactly 22 (its square is gp11g^{p-1}\equiv1, and it is not itself 1\equiv1 since gg has order p1p-1, not a divisor (p1)/2\le(p-1)/2), so g(p1)/21(modp)g^{(p-1)/2}\equiv-1\pmod p (the only order-22 element in (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times). Then a(p1)/2=(g(p1)/2)k(1)k=1(modp)a^{(p-1)/2}=(g^{(p-1)/2})^k \equiv(-1)^k=-1\pmod p since kk is odd. Both cases match (ap)\left(\frac ap\right). \blacksquare

Corollary 5.8 (Multiplicativity). (abp)=(ap)(bp)\left(\dfrac{ab}p\right) = \left(\dfrac ap\right)\left(\dfrac bp\right), immediate from Euler's Criterion since (ab)(p1)/2=a(p1)/2b(p1)/2(ab)^{(p-1)/2}=a^{(p-1)/2}b^{(p-1)/2}.

Corollary 5.9 (First Supplementary Law). (1p)=(1)(p1)/2\left(\dfrac{-1}p\right) = (-1)^{(p-1)/2}, i.e. 1-1 is a QR mod pp iff p1(mod4)p\equiv1\pmod4 — recovering Challenge Problem 2.2 by a one-line argument.

5.4 The Law of Quadratic Reciprocity

Theorem 5.10 (Quadratic Reciprocity). For distinct odd primes p,qp,q:
(pq)(qp)=(1)p12q12.\left(\frac pq\right)\left(\frac qp\right) = (-1)^{\frac{p-1}2\cdot\frac{q-1}2}.
Equivalently, (pq)=(qp)\left(\frac pq\right)=\left(\frac qp\right) unless both pq3(mod4)p\equiv q\equiv3\pmod4, in which case (pq)=(qp)\left(\frac pq\right)=-\left(\frac qp\right).

Supplementary Laws.
(1p)=(1)(p1)/2,(2p)=(1)(p21)/8,\left(\frac{-1}p\right)=(-1)^{(p-1)/2}, \qquad \left(\frac2p\right) = (-1)^{(p^2-1)/8},
i.e. 22 is a QR mod pp iff p±1(mod8)p\equiv\pm1\pmod8.

On the proof. Gauss gave (over his lifetime) eight distinct proofs. The classical elementary route uses Gauss's Lemma — counting how many of the least-magnitude residues of a,2a,,p12a(modp)a,2a,\dots,\frac{p-1}2 a\pmod p are negative — combined with a lattice-point-counting argument (Eisenstein's version) comparing the two primes' contributions. This proof, while fully elementary, is long; we state the theorem, name the method (Gauss's Lemma + lattice-point counting), and turn to its use, which is where the real computational power lies.

Worked Example 5.2. Is 219219 a QR mod 383383 (383383 is prime)? Factor 219=3×73219=3\times73, so (219383)=(3383)(73383)\left(\frac{219}{383}\right)=\left(\frac3{383}\right)\left(\frac{73}{383}\right).

For (3383)\left(\frac3{383}\right): since 3833(mod4)383\equiv3\pmod4 and 33(mod4)3\equiv3\pmod4, reciprocity flips sign: (3383)=(3833)=(23)\left(\frac3{383}\right)=-\left(\frac{383}3\right)=-\left(\frac23\right) (as 3832(mod3)383\equiv2\pmod3). Since 33(mod8)3\equiv3\pmod8, 22 is a NQR mod 33 (directly: squares mod 3 are {0,1}\{0,1\}), so (23)=1\left(\frac23\right)=-1, giving (3383)=(1)=1\left(\frac3{383}\right)=-(-1)=1.

For (73383)\left(\frac{73}{383}\right): 731(mod4)73\equiv1\pmod4, so reciprocity does not flip sign: (73383)=(38373)\left(\frac{73}{383}\right)=\left(\frac{383}{73}\right). Now 383=573+18383 = 5\cdot73+18, so (38373)=(1873)=(273)(973)=(273)1\left(\frac{383}{73}\right)=\left(\frac{18}{73}\right)=\left(\frac2{73}\right)\left(\frac9{73}\right)=\left(\frac2{73}\right)\cdot1 (as 9=329=3^2 is a perfect square). Since 731(mod8)73\equiv1\pmod8, (273)=1\left(\frac2{73}\right)=1. So (73383)=1\left(\frac{73}{383}\right)=1.

Combining: (219383)=1×1=1\left(\frac{219}{383}\right)=1\times1=1219219 is a QR mod 383383. \blacksquare

Trick. This example illustrates the standard computational algorithm: factor out squares and small primes, apply reciprocity to flip each odd-prime symbol into a smaller modulus, and recurse — precisely mirroring the Euclidean Algorithm in structure and speed (O(logp)O(\log p) reciprocity/reduction steps).

5.5 Challenge Problems

Challenge Problem 5.1 (IMO 1990, Problem 3). Find all positive integers nn such that n22n+1n^2 \mid 2^n+1.

Solution. We claim the answers are n=1n=1 and n=3n=3.

Step 0. 2n+12^n+1 is always odd, so n2n^2 must be odd, hence nn is odd. n=1n=1 works trivially (131\mid3). Assume now n>1n>1.

Step 1 (the smallest prime factor of nn is 33). Let pp be the smallest prime dividing nn; pp is odd. Since pn2n+1p\mid n \mid 2^n+1, we have 2n1(modp)2^n\equiv-1\pmod p, so 22n1(modp)2^{2n}\equiv1\pmod p. Let d=ordp(2)d=\operatorname{ord}_p(2). Then d2nd\mid2n but dnd\nmid n (else 2n12^n\equiv1, contradicting 2n1≢12^n\equiv-1\not\equiv1 as p>2p>2); also dp1d\mid p-1 (Proposition 5.4 with φ(p)=p1\varphi(p)=p-1). Every prime factor of dd is dp1<p\le d\le p-1<p, so — since pp is the smallest prime factor of nndd shares no prime factor with nn, i.e. gcd(d,n)=1\gcd(d,n)=1. Combined with d2nd\mid2n, this forces d2d\mid2. Since d1d\neq1 (2≢1(modp)2\not\equiv1\pmod p), d=2d=2, so p221=3p\mid2^2-1=3: p=3p=3.

Step 2 (exact power of 33 dividing nn). Let a=v3(n)1a=v_3(n)\ge1. By LTE (Corollary 5.2, since 3(2+1)3\mid(2+1) and nn is odd),
v3(2n+1)=v3(2+1)+v3(n)=1+a.v_3(2^n+1) = v_3(2+1)+v_3(n) = 1+a.
Since n22n+1n^2\mid2^n+1 requires v3(n2)=2a1+av_3(n^2)=2a \le 1+a, we get a1a\le1, so a=1a=1: write n=3mn=3m with 3m3\nmid m.

Step 3 (m=1m=1). Suppose m>1m>1 and let qq be the smallest prime factor of mm; then q3q\neq3, and every prime factor of nn is either 33 or q\ge q (since qq is the smallest prime factor of mm). Let d=ordq(2)d'=\operatorname{ord}_q(2); as in Step 1, d2nd'\mid2n, dnd'\nmid n, dq1d'\mid q-1, and every prime factor of dd' is <q<q. So dd' can only share the prime 33 with nn (all other prime factors of nn being q>d\ge q>d''s factors). Write d=3std'=3^st with 3t3\nmid t; since d2n=6md'\mid2n=6m and v3(6m)=1v_3(6m)=1, we get s1s\le1.

  • If s=0s=0: gcd(d,n)=1\gcd(d',n)=1, so as in Step 1, d2d'\mid2, giving d=2d'=2, so q221=3q\mid2^2-1=3 — contradicting q3q\neq3.
  • If s=1s=1: d=3td'=3t with t2mt\mid2m and gcd(t,m)=1\gcd(t,m)=1 (its prime factors being <q<q\le all prime factors of mm), so t2t\mid2, giving t{1,2}t\in\{1,2\}, i.e. d{3,6}d'\in\{3,6\}.
    • d=3d'=3: then q231=7q\mid2^3-1=7, so q=7q=7. But ord7(2)=3\operatorname{ord}_7(2)=3 (since 23=81(mod7)2^3=8\equiv1\pmod7) is odd, so the cyclic subgroup generated by 22 mod 77 has odd order and cannot contain 1-1 (which has order 22) — so 2n1(mod7)2^n\equiv-1\pmod7 is never solvable. Contradiction.
    • d=6d'=6: then q261=63=327q\mid2^6-1=63=3^2\cdot7, so q=7q=7 again; but we just computed ord7(2)=36\operatorname{ord}_7(2)=3\neq6. Contradiction.

Both sub-cases fail, so m=1m=1 is forced: n=3n=3.

Conclusion: the solutions are n=1 and n=3\boxed{n=1 \text{ and } n=3} (check: 23+1=9=322^3+1=9=3^2 \checkmark). \blacksquare

Challenge Problem 5.2. For an odd prime pp, evaluate
T=k=0p1(k2+kp).T = \sum_{k=0}^{p-1} \left(\frac{k^2+k}{p}\right).

Solution. The terms k=0k=0 and k=p1k=p-1 both contribute 00 (since k2+k=k(k+1)0(modp)k^2+k=k(k+1)\equiv0\pmod p there), so
T=k=1p2(k(k+1)p).T = \sum_{k=1}^{p-2} \left(\frac{k(k+1)}p\right).
For k{1,,p2}k\in\{1,\dots,p-2\}, kk is invertible mod pp, so we may write k(k+1)=k2(1+k1)k(k+1) = k^2(1+k^{-1}), giving (using multiplicativity, Corollary 5.8, and (k2p)=1\left(\frac{k^2}p\right)=1):
(k(k+1)p)=(1+k1p).\left(\frac{k(k+1)}p\right) = \left(\frac{1+k^{-1}}p\right).
As kk ranges over {1,,p2}\{1,\dots,p-2\} (i.e. all nonzero residues except p1p-1), its inverse k1k^{-1} also ranges over all nonzero residues except the inverse of p1p-1 — and (p1)1p1(modp)(p-1)^{-1}\equiv p-1\pmod p (since (p1)21(p-1)^2\equiv1), so k1k^{-1} ranges over exactly the same set {1,,p2}\{1,\dots,p-2\}, just relabeled. Substituting j=k1j=k^{-1}:
T=j=1p2(1+jp)=i=2p1(ip)=[i=1p1(ip)](1p)=01=1,T = \sum_{j=1}^{p-2}\left(\frac{1+j}p\right) = \sum_{i=2}^{p-1}\left(\frac ip\right) = \left[\sum_{i=1}^{p-1}\left(\frac ip\right)\right] - \left(\frac1p\right) = 0 - 1 = -1,
using the standard fact that i=1p1(ip)=0\sum_{i=1}^{p-1}\left(\frac ip\right)=0 (there are exactly p12\frac{p-1}2 QRs and p12\frac{p-1}2 NQRs, contributing equal numbers of +1+1's and 1-1's).

Conclusion: T=1T=-1 for every odd prime pp. \blacksquare

Verification (p=5p=5): QRs mod 55 are {1,4}\{1,4\}. Terms k=0,,4k=0,\dots,4: k(k+1)=0,2,61,122,200k(k+1)=0,2,6\equiv1,12\equiv2,20\equiv0, giving Legendre symbols 0,1,1,1,00,-1,1,-1,0, summing to 1-1. \checkmark


Appendix A — Master Formula Sheet

Divisibility and the Euclidean Algorithm
a=bq+r, 0r<bgcd(a,b)=gcd(b,amodb)gcd(a,b)lcm(a,b)=aba=bq+r,\ 0\le r<b \qquad \gcd(a,b)=\gcd(b,a\bmod b) \qquad \gcd(a,b)\cdot\operatorname{lcm}(a,b)=ab
ax+by=gcd(a,b) has an integer solution (Beˊzout)gcd(a,b)=1    x,y: ax+by=1ax+by=\gcd(a,b) \text{ has an integer solution (Bézout)} \qquad \gcd(a,b)=1 \iff \exists\, x,y:\ ax+by=1

Prime Factorization
n=ipiai(unique)gcd(a,b)=pmin(vpa,vpb)lcm(a,b)=pmax(vpa,vpb)n = \prod_i p_i^{a_i} \quad\text{(unique)} \qquad \gcd(a,b)=\prod p^{\min(v_p a,v_p b)} \qquad \operatorname{lcm}(a,b)=\prod p^{\max(v_p a,v_p b)}

Congruences
ab(modm)    m(ab)axb(modm) solvable    gcd(a,m)b (then gcd(a,m) solutions)a\equiv b\pmod m \iff m\mid(a-b) \qquad ax\equiv b\pmod m \text{ solvable} \iff \gcd(a,m)\mid b\ (\text{then } \gcd(a,m) \text{ solutions})

Chinese Remainder Theorem
xai(modmi) (pairwise coprime mi)    xaiMiyi(modM),  Mi=Mmi, Miyi1(modmi)x\equiv a_i\pmod{m_i}\ (\text{pairwise coprime } m_i) \implies x\equiv \sum a_iM_iy_i \pmod{M},\ \ M_i=\tfrac{M}{m_i},\ M_iy_i\equiv1\pmod{m_i}

Classical Theorems
ap11(modp) (Fermat)aφ(n)1(modn) (Euler)(p1)!1(modp) (Wilson)a^{p-1}\equiv1\pmod p\ (\text{Fermat}) \qquad a^{\varphi(n)}\equiv1\pmod n\ (\text{Euler}) \qquad (p-1)!\equiv-1\pmod p\ (\text{Wilson})
aeaemodφ(m)(modm) if gcd(a,m)=1;aeaφ(m)+(emodφ(m))(modm) if elog2m (any a)a^e\equiv a^{e\bmod\varphi(m)}\pmod m \text{ if } \gcd(a,m)=1;\quad a^e\equiv a^{\varphi(m)+(e\bmod\varphi(m))}\pmod m \text{ if } e\ge\log_2 m \text{ (any } a)

Multiplicative Functions (n=piain=\prod p_i^{a_i})
τ(n)=(ai+1)σ(n)=piai+11pi1φ(n)=npn(11p)dnφ(d)=n\tau(n)=\prod(a_i+1) \qquad \sigma(n)=\prod\frac{p_i^{a_i+1}-1}{p_i-1} \qquad \varphi(n)=n\prod_{p\mid n}\left(1-\frac1p\right) \qquad \sum_{d\mid n}\varphi(d)=n
τ=11σ=id1φ1=idμ1=ε\tau=\mathbf1*\mathbf1 \qquad \sigma=\operatorname{id}*\mathbf1 \qquad \varphi*\mathbf1=\operatorname{id} \qquad \mu*\mathbf1=\varepsilon
g=f1    f=gμ(Mo¨bius Inversion)d=1Nμ(d)Nd=1g=f*\mathbf1 \implies f = g*\mu \quad\text{(Möbius Inversion)} \qquad \sum_{d=1}^N \mu(d)\left\lfloor\frac Nd\right\rfloor = 1
i=1nj=1ngcd(i,j)=d=1nφ(d)nd2\sum_{i=1}^n\sum_{j=1}^n\gcd(i,j) = \sum_{d=1}^n \varphi(d)\left\lfloor\frac nd\right\rfloor^2

Diophantine Equations
ax+by=c solvable    gcd(a,b)c;x=x0+bdt, y=y0adtax+by=c \text{ solvable} \iff \gcd(a,b)\mid c;\quad x=x_0+\tfrac bd t,\ y=y_0-\tfrac ad t
Primitive Pythagorean triples: x=m2n2, y=2mn, z=m2+n2  (gcd(m,n)=1, m≢n ⁣ ⁣(mod2))\text{Primitive Pythagorean triples: } x=m^2-n^2,\ y=2mn,\ z=m^2+n^2\ \ (\gcd(m,n)=1,\ m\not\equiv n\!\!\pmod2)
Pell: xk+ykd=(x1+y1d)kx4+y4=z2 has no positive solution\text{Pell: } x_k+y_k\sqrt d = (x_1+y_1\sqrt d)^k \qquad x^4+y^4=z^2 \text{ has no positive solution}
p1 ⁣ ⁣(mod4)    p=a2+b2y2+2=x3    (x,y)=(3,±5) onlyp\equiv1\!\!\pmod4 \iff p=a^2+b^2 \qquad y^2+2=x^3 \implies (x,y)=(3,\pm5) \text{ only}

LTE (odd prime pp, pxyp\mid x-y, px,yp\nmid x,y)
vp(xnyn)=vp(xy)+vp(n)vp(xn+yn)=vp(x+y)+vp(n)  (n odd,px+y)v_p(x^n-y^n)=v_p(x-y)+v_p(n) \qquad v_p(x^n+y^n)=v_p(x+y)+v_p(n)\ \ (n \text{ odd}, p\mid x+y)
p=2:v2(xnyn)=v2(xy) (n odd);v2(xy)+v2(x+y)+v2(n)1 (n even)p=2:\quad v_2(x^n-y^n)=v_2(x-y)\ (n \text{ odd}); \quad v_2(x-y)+v_2(x+y)+v_2(n)-1\ (n \text{ even})

Orders, Primitive Roots, Quadratic Residues
ordn(a)φ(n)primitive roots exist for n{1,2,4,pk,2pk}\operatorname{ord}_n(a)\mid\varphi(n) \qquad \text{primitive roots exist for } n\in\{1,2,4,p^k,2p^k\}
a(p1)/2(ap)(modp) (Euler)(abp)=(ap)(bp)(1p)=(1)(p1)/2(2p)=(1)(p21)/8a^{(p-1)/2}\equiv\left(\frac ap\right)\pmod p\ \text{(Euler)} \qquad \left(\frac{ab}p\right)=\left(\frac ap\right)\left(\frac bp\right) \qquad \left(\frac{-1}p\right)=(-1)^{(p-1)/2}\qquad \left(\frac2p\right)=(-1)^{(p^2-1)/8}
(pq)(qp)=(1)p12q12 (Quadratic Reciprocity)\left(\frac pq\right)\left(\frac qp\right)=(-1)^{\frac{p-1}2\frac{q-1}2}\ \text{(Quadratic Reciprocity)}


Closing Remark: A Unifying Theme

Every construction in this treatise is a shadow of a single algebraic fact: Z\mathbb{Z} is a Euclidean domain. The Division Algorithm (Theorem 1.1) is precisely the defining property of a Euclidean domain; Bézout's Identity and unique factorization (Theorems 1.5, 1.9) are its immediate structural consequences, and every Euclidean domain is automatically a principal ideal domain (PID) and hence a unique factorization domain (UFD). When we write gcd(a,b)=ax+by\gcd(a,b)=ax+by, we are really exhibiting the ideal (a,b)Z(a,b)\subseteq\mathbb{Z} as the principal ideal (gcd(a,b))(\gcd(a,b)) — Bézout's Identity is the statement that ideals in Z\mathbb{Z} are principal.

Modular arithmetic is the passage to quotient rings: Z/nZ\mathbb{Z}/n\mathbb{Z}. A prime pp is precisely a value of nn for which the ideal (p)(p) is maximal (equivalently prime), and correspondingly Z/pZ\mathbb{Z}/p\mathbb{Z} is not merely a ring but a field — this is exactly why polynomials over Z/pZ\mathbb{Z}/p\mathbb{Z} have at most as many roots as their degree (used decisively in Theorem 5.5), a property that can fail over Z/nZ\mathbb{Z}/n\mathbb{Z} for composite nn. The group of units (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times has order φ(n)\varphi(n), and Euler's Theorem is nothing but Lagrange's Theorem from group theory ("the order of an element divides the order of the group") applied to this group — the same abstract fact that, applied to the cyclic group generated by a primitive root, structures all of Part V.

Diophantine equations, in turn, push this machinery outward: when Z\mathbb{Z} itself is too small to factor an expression like x2+y2x^2+y^2 or y2+2y^2+2, we pass to a larger ring of algebraic integers — Z[i]\mathbb{Z}[i], Z[2]\mathbb{Z}[\sqrt{-2}] — and ask whether unique factorization still holds there. When it does (as in both our examples, each a Euclidean domain in its own right), the same Bézout/UFD machinery that solved everything in Part I solves equations invisible to elementary methods. When it does not — as happens already for rings like Z[5]\mathbb{Z}[\sqrt{-5}] — mathematicians in the 19th century were forced to invent ideals in the modern sense (Kummer's "ideal numbers," formalized by Dedekind) precisely to restore unique factorization, this time at the level of ideals rather than elements. This is the birth of algebraic number theory.

Finally, Quadratic Reciprocity — stated but not fully proved here — is now understood as the first, and simplest, instance of a vast unification called class field theory and, more generally, the Artin Reciprocity Law, which describes how primes split in abelian extensions of number fields in terms of data purely internal to the base field. Seen this way, the question "is aa a square mod pp?" and the question "how does pp factor in Z[a]\mathbb{Z}[\sqrt a]?" are the same question — the theme first glimpsed in Section 4.5, where "1-1 is a QR mod pp" and "pp splits in Z[i]\mathbb{Z}[i]" turned out to be identical statements in different languages.

In short: discrete number theory — divisibility, congruences, quadratic residues — is the visible surface of continuous algebraic structure: rings, ideals, and groups. Every theorem in this treatise can be re-read, without changing a single line of logic, as a theorem about the ring Z\mathbb{Z}; and every generalization worth pursuing next asks the same question of a larger ring.

\blacksquare

+
+
+
+