Number Theory Basics

⚡ Key Takeaways

Number theory is the study of the integers Z\mathbb{Z} and their arithmetic structure: divisibility, primes, congruences, and Diophantine equations. Key result: every integer >1>1 factors uniquely into primes (the Fundamental Theorem of Arithmetic). Applies to: cryptography, coding theory, computer science, and pure mathematics. Origins: Euclid (c. 300 BCE), systematized by Gauss in Disquisitiones Arithmeticae (1801).

💡 The Core Insight

The integers form a structure where addition is simple but multiplication is profound. The primes are the indecomposable building blocks under multiplication, and the Fundamental Theorem of Arithmetic says every integer is uniquely assembled from them. Most of elementary number theory flows from two engines: the division algorithm (which controls divisibility and the GCD) and modular arithmetic (which packages divisibility relations into a clean algebraic system Z/nZ\mathbb{Z}/n\mathbb{Z}).

Formal Statement

DefinitionDivisibility

For integers a,ba, b with a≠0a \neq 0, we say aa divides bb, written a∣ba \mid b, if there exists an integer kk such that:

1
b=a k,k∈Z\quad b = a\,k, \qquad k \in \mathbb{Z}

Derivation hint: This is a definition; the symbol a∣ba\mid b asserts existence of the integer quotient k=b/ak=b/a. If no such integer exists, write a∤ba \nmid b. Here aa is a divisor (or factor) of bb, and bb is a multiple of aa. Basic properties: a∣aa\mid a (reflexive on nonzero aa); if a∣ba\mid b and b∣cb\mid c then a∣ca\mid c (transitive); if a∣ba\mid b and a∣ca\mid c then a∣(mb+nc)a\mid (mb+nc) for all m,n∈Zm,n\in\mathbb{Z} (linearity).

DefinitionPrime and Composite

An integer p>1p>1 is prime if its only positive divisors are 11 and pp. An integer n>1n>1 that is not prime is composite. The number 11 is a unit and is neither prime nor composite.

TheoremDivision Algorithm

For any integers aa and bb with b>0b>0, there exist unique integers qq (quotient) and rr (remainder) such that:

2
a=b q+r,0≤r<b\quad a = b\,q + r, \qquad 0 \le r < b

Derivation hint: Take q=⌊a/b⌋q = \lfloor a/b\rfloor, the greatest integer not exceeding a/ba/b; then r=a−bqr = a - bq automatically satisfies 0≤r<b0\le r<b. Uniqueness follows from comparing two such representations.

TheoremFundamental Theorem of Arithmetic

Every integer n>1n>1 can be written as a product of primes, and this representation is unique up to the order of the factors:

3
n=p1a1p2a2⋯pkak,p1<p2<⋯<pk,  ai≥1\quad n = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}, \qquad p_1 < p_2 < \cdots < p_k,\ \ a_i \ge 1

Derivation hint: Existence is by strong induction (split any composite into smaller factors). Uniqueness rests on Euclid's Lemma: if a prime p∣abp\mid ab then p∣ap\mid a or p∣bp\mid b.

DefinitionGreatest Common Divisor and Bézout's Identity

The greatest common divisor gcd⁡(a,b)\gcd(a,b) is the largest positive integer dividing both aa and bb. Bézout's identity states there exist integers x,yx,y with:

4
gcd⁡(a,b)=a x+b y\quad \gcd(a,b) = a\,x + b\,y

Derivation hint: gcd⁡(a,b)\gcd(a,b) is the smallest positive value of the set {ax+by:x,y∈Z}\{ax+by : x,y\in\mathbb{Z}\}; minimality plus the division algorithm forces it to divide both aa and bb. Two integers are coprime (relatively prime) if gcd⁡(a,b)=1\gcd(a,b)=1.

DefinitionCongruence Modulo n

For a positive integer nn, integers aa and bb are congruent modulo nn, written a≡b(modn)a \equiv b \pmod{n}, if:

5
n∣(a−b)\quad n \mid (a - b)

Derivation hint: Equivalently, aa and bb leave the same remainder when divided by nn (apply the division algorithm to each). Congruence is an equivalence relation that respects addition and multiplication, partitioning Z\mathbb{Z} into nn residue classes forming the ring Z/nZ\mathbb{Z}/n\mathbb{Z}.

TheoremFermat's Little Theorem

If pp is prime and gcd⁡(a,p)=1\gcd(a,p)=1, then:

6
ap−1≡1(modp)\quad a^{p-1} \equiv 1 \pmod{p}

Derivation hint: The nonzero residues {1,2,…,p−1}\{1,2,\dots,p-1\} are permuted by multiplication by aa; multiplying them all together and cancelling the common factor yields ap−1≡1a^{p-1}\equiv 1.

TheoremEuler's Theorem

If gcd⁡(a,n)=1\gcd(a,n)=1, then aφ(n)≡1(modn)a^{\varphi(n)} \equiv 1 \pmod{n}, where Euler's totient counts integers in [1,n][1,n] coprime to nn:

7
φ(n)=n∏p∣n(1−1p)\quad \varphi(n) = n \prod_{p \mid n}\left(1 - \frac{1}{p}\right)

Derivation hint: The product runs over distinct primes dividing nn; it follows from φ\varphi being multiplicative and φ(pk)=pk−pk−1\varphi(p^k)=p^k-p^{k-1}. The theorem generalizes Fermat's by replacing p−1p-1 with φ(n)\varphi(n).

TheoremChinese Remainder Theorem

If n1,n2,…,nkn_1, n_2, \dots, n_k are pairwise coprime, the system x≡ai(modni)x \equiv a_i \pmod{n_i} has a unique solution modulo the product:

8
x≡∑i=1kai Ni Mi(modN),N=∏ini,  Ni=N/ni,  Mi≡Ni−1(modni)\quad x \equiv \sum_{i=1}^{k} a_i\, N_i\, M_i \pmod{N}, \qquad N = \prod_i n_i,\ \ N_i = N/n_i,\ \ M_i \equiv N_i^{-1} \pmod{n_i}

Derivation hint: Each term aiNiMia_iN_iM_i equals aia_i mod nin_i (since NiMi≡1N_iM_i\equiv1) and vanishes mod every other njn_j (since nj∣Nin_j\mid N_i). Summing gives the full solution.

Why It Holds

ProofEuclid's Theorem: Infinitely Many Primes

We show no finite list of primes is complete. 1. Suppose, for contradiction, that there are only finitely many primes: p1,p2,…,pnp_1, p_2, \dots, p_n. 2. Form the integer N=p1p2⋯pn+1N = p_1 p_2 \cdots p_n + 1. 3. By the Fundamental Theorem of Arithmetic, N>1N>1 has at least one prime divisor qq. 4. If qq were one of the listed primes pip_i, then q∣(N−p1⋯pn)=1q \mid (N - p_1\cdots p_n) = 1, which is impossible since no prime divides 11. 5. Therefore qq is a prime not in our list — contradicting the assumption that the list was complete. 6. Hence the set of primes is infinite. ■\blacksquare

∎
ProofEuclidean Algorithm computes the GCD

The algorithm repeatedly applies the division algorithm to find gcd⁡(a,b)\gcd(a,b). 1. Given a≥b>0a \ge b > 0, write a=bq+ra = bq + r with 0≤r<b0 \le r < b (equation [2]). 2. Key lemma: gcd⁡(a,b)=gcd⁡(b,r)\gcd(a,b) = \gcd(b,r). Proof: any common divisor of a,ba,b divides r=a−bqr=a-bq; any common divisor of b,rb,r divides a=bq+ra=bq+r. The two pairs share the same divisors, hence the same greatest one. 3. Replace (a,b)(a,b) by (b,r)(b,r) and repeat. The remainders strictly decrease: b>r1>r2>⋯≥0b > r_1 > r_2 > \cdots \ge 0. 4. Since a strictly decreasing sequence of nonnegative integers must terminate, some remainder reaches 00. 5. When rk=0r_k = 0, we have gcd⁡(… )=gcd⁡(rk−1,0)=rk−1\gcd(\dots) = \gcd(r_{k-1}, 0) = r_{k-1}, the last nonzero remainder. ■\blacksquare

∎
CF
Carl Friedrich Gauss
1777–1855

Gauss called mathematics "the queen of the sciences" and number theory "the queen of mathematics." At age 24 he published Disquisitiones Arithmeticae (1801), which introduced the congruence notation a≡b(modn)a\equiv b\pmod n, systematized modular arithmetic, proved the law of quadratic reciprocity (which he called the aureum theorema, golden theorem, and proved in multiple ways throughout his life), and laid the foundations for algebraic number theory. His insistence on rigorous proof transformed number theory from a collection of clever observations into a coherent discipline. He reputedly remarked that he discovered the prime-counting estimate π(x)≈x/ln⁡x\pi(x)\approx x/\ln x as a teenager.

Building Intuition

🧠 Intuition

Think of the primes as a periodic table of integers: every number is a unique molecule built from prime atoms. The exponents in the prime factorization [3] are coordinates locating each integer in an infinite-dimensional grid (one axis per prime). Divisibility a∣ba\mid b then means aa's coordinates are all ≤b\le b's, coordinate-by-coordinate — the GCD takes the minimum exponent in each slot, the LCM takes the maximum. Modular arithmetic, meanwhile, is just clock arithmetic: on a 12-hour clock, 9+5=29 + 5 = 2 because 14≡2(mod12)14 \equiv 2 \pmod{12}. The Chinese Remainder Theorem says that knowing the time on several coprime clocks (mod 7, mod 11, mod 13) pins down the absolute "time" uniquely up to the product 7⋅11⋅13=10017\cdot 11\cdot 13 = 1001.

Figure
The sieve of Eratosthenes: composites struck out as multiples of each prime, leaving primes (gold) standing.
Integers 2–31 after sieving multiples of 2, 3, 5 2 3 5 7 11 13 17 19 23 29 31 4 6 9 15 21 25 27 Gold = prime (survives all crossings) Struck = composite (a multiple of some smaller prime)

Worked Examples

ExampleSolving a Linear Congruence with the Extended Euclidean Algorithm

Given: Solve 17x≡5(mod43)17x \equiv 5 \pmod{43}.

Step 1 — Find the inverse of 17 mod 43. Apply the Euclidean algorithm:

  • 43=2⋅17+943 = 2\cdot 17 + 9
  • 17=1⋅9+817 = 1\cdot 9 + 8
  • 9=1⋅8+19 = 1\cdot 8 + 1
  • 8=8⋅1+08 = 8\cdot 1 + 0, so gcd⁡(17,43)=1\gcd(17,43)=1 (an inverse exists).

Step 2 — Back-substitute (Bézout, equation [4]):

  • 1=9−1⋅81 = 9 - 1\cdot 8
  • =9−(17−9)=2⋅9−17= 9 - (17 - 9) = 2\cdot 9 - 17
  • =2(43−2⋅17)−17=2⋅43−5⋅17= 2(43 - 2\cdot 17) - 17 = 2\cdot 43 - 5\cdot 17.

So −5⋅17≡1(mod43)-5\cdot 17 \equiv 1 \pmod{43}, giving 17−1≡−5≡38(mod43)17^{-1} \equiv -5 \equiv 38 \pmod{43}.

Step 3 — Multiply both sides by the inverse:

x≡38⋅5=190≡190−4⋅43=190−172=18(mod43).x \equiv 38\cdot 5 = 190 \equiv 190 - 4\cdot 43 = 190 - 172 = 18 \pmod{43}.

Check: 17⋅18=306=7⋅43+5=301+517\cdot 18 = 306 = 7\cdot 43 + 5 = 301 + 5, so 17⋅18≡517\cdot 18 \equiv 5. ✓

x≡18(mod43)\boxed{x \equiv 18 \pmod{43}}
ExampleFast Modular Exponentiation via Fermat's Little Theorem

Given: Compute 7222  117^{222} \bmod 11.

Step 1 — Apply Fermat's Little Theorem (equation [6]). Since 1111 is prime and gcd⁡(7,11)=1\gcd(7,11)=1:

710≡1(mod11).7^{10} \equiv 1 \pmod{11}.

Step 2 — Reduce the exponent modulo 10:

222=22⋅10+2,so7222=(710)22⋅72≡122⋅72(mod11).222 = 22\cdot 10 + 2, \quad\text{so}\quad 7^{222} = (7^{10})^{22}\cdot 7^{2} \equiv 1^{22}\cdot 7^2 \pmod{11}.

Step 3 — Evaluate the residual power:

72=49=4⋅11+5≡5(mod11).7^2 = 49 = 4\cdot 11 + 5 \equiv 5 \pmod{11}.
7222≡5(mod11)\boxed{7^{222} \equiv 5 \pmod{11}}

Common Misconceptions

⚠️ Common mistake

"The number 1 is prime." It is not. Declaring 11 prime would destroy the uniqueness in the Fundamental Theorem of Arithmetic ([3]), since you could append any number of factors of 11 (e.g., 6=2⋅3=1⋅2⋅3=1⋅1⋅2⋅36 = 2\cdot 3 = 1\cdot 2\cdot 3 = 1\cdot 1\cdot 2\cdot 3). The number 11 is a unit: it has a multiplicative inverse and is excluded from the primes precisely to preserve unique factorization.

⚠️ Common mistake

"a≡b(modn)a \equiv b \pmod n lets you always cancel a common factor." Cancellation is only valid when the factor is coprime to the modulus. From 6≡6(mod4)6 \equiv 6 \pmod 4, you may not divide by 22 to conclude 3≡3(mod4)3\equiv 3\pmod 4 via 62≡62(mod42)\frac{6}{2}\equiv\frac{6}{2}\pmod{\frac42} carelessly. The correct rule: if ca≡cb(modn)ca\equiv cb\pmod n then a≡b(modn/gcd⁡(c,n))a\equiv b\pmod{n/\gcd(c,n)}.

Counterexample

The converse of Fermat's Little Theorem fails. One might hope that an−1≡1(modn)a^{n-1}\equiv 1\pmod n for some aa guarantees nn is prime. But n=341=11⋅31n = 341 = 11\cdot 31 is composite, yet 2340≡1(mod341)2^{340}\equiv 1 \pmod{341}. Such nn are called Fermat pseudoprimes (base 2). Worse, Carmichael numbers like 561=3⋅11⋅17561 = 3\cdot 11\cdot 17 satisfy a560≡1(mod561)a^{560}\equiv 1\pmod{561} for every aa coprime to 561561, fooling the Fermat test for all bases. This is why probabilistic primality tests use the stronger Miller–Rabin criterion.

Connections

connection

Number theory sits at a crossroads of mathematics. The ring Z/nZ\mathbb{Z}/n\mathbb{Z} and the group of units (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times are the entry point to Abstract Algebra, where the GCD's Bézout identity reappears as the theory of ideals in Principal Ideal Domains. The distribution of primes, captured by the Prime Number Theorem π(x)∼x/ln⁡x\pi(x)\sim x/\ln x, links elementary number theory to Complex Analysis through the Riemann zeta function. Quadratic reciprocity opens into Algebraic Number Theory, where unique factorization is recovered for ideals when it fails for elements. Congruences and the Chinese Remainder Theorem are the computational heart of Cryptography and Coding Theory.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- c. 1800 BCE — Babylonian tablet Plimpton 322 lists Pythagorean triples, an early Diophantine table.
- c. 300 BCE — Euclid's Elements (Books VII–IX) gives the Euclidean algorithm, the proof of infinitely many primes, and the link between primes and perfect numbers.
- c. 250 CE — Diophantus of Alexandria writes Arithmetica, founding the study of integer/rational solutions of equations.
- 1640 — Pierre de Fermat states his "Little Theorem" and his famous "Last Theorem" margin note; corresponds prolifically on number theory.
- 1736 — Leonhard Euler proves Fermat's Little Theorem and introduces the totient function φ(n)\varphi(n).
- 1801 — Gauss publishes Disquisitiones Arithmeticae, introducing congruence notation and proving quadratic reciprocity.
- 1837 — Dirichlet proves infinitely many primes in any arithmetic progression a,a+d,a+2d,…a, a+d, a+2d,\dots with gcd⁡(a,d)=1\gcd(a,d)=1, launching analytic number theory.
- 1859 — Riemann's eight-page memoir connects π(x)\pi(x) to the zeros of ζ(s)\zeta(s), posing the Riemann Hypothesis.
- 1896 — Hadamard and de la Vallée Poussin independently prove the Prime Number Theorem.
- 1994 — Andrew Wiles proves Fermat's Last Theorem via modularity of elliptic curves, vindicating Fermat's 1637 claim.

Subtleties & Limits

open-problem

Many of number theory's most natural questions remain open. The Riemann Hypothesis — that all nontrivial zeros of ζ(s)\zeta(s) have real part 12\tfrac12 — controls the finest error term in the distribution of primes and is one of the seven Millennium Prize Problems. The Twin Prime Conjecture asserts infinitely many pairs (p,p+2)(p, p+2) of primes; Yitang Zhang (2013) proved bounded gaps occur infinitely often, later sharpened by the Polymath project to gaps of size ≤246\le 246, but the gap of 22 remains unproven. Goldbach's Conjecture (every even integer >2>2 is a sum of two primes) is verified to enormous bounds but unproven. The abc conjecture, deciding the structure behind additive-multiplicative interactions, has a disputed claimed proof. These show that the integers, the simplest objects in mathematics, still harbor profound mysteries.

See Also

Modular Arithmetic · Prime Number Theorem · Diophantine Equations · Quadratic Reciprocity · Continued Fractions · Euler's Totient Function · Elliptic Curves