Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Number theory is the branch of pure mathematics studying the integers and integer-valued functions. Classical results about primes and divisibility underlie modern cryptography and computer science.


1. Integers and Divisibility

For integers aa and bb with b0b \neq 0, we say bb divides aa (written bab \mid a) if there exists an integer kk such that a=kba = kb.

1.1 Division Algorithm

For any integers aa and b>0b > 0, there exist unique integers qq (quotient) and rr (remainder) with 0r<b0 \leq r < b such that:

a=qb+ra = qb + r

1.2 Greatest Common Divisor (GCD)

The GCD of two integers a,ba, b (not both zero) is the largest positive integer dividing both.

Euclidean algorithm — the most efficient classical method:

gcd(a,b)=gcd(b,  amodb)gcd(a,0)=a\begin{align} \gcd(a, b) &= \gcd(b,\; a \bmod b) \\ \gcd(a, 0) &= a \end{align}

Least Common Multiple:

lcm(a,b)=abgcd(a,b)\operatorname{lcm}(a, b) = \frac{|ab|}{\gcd(a, b)}

Bézout’s identity: There always exist integers s,ts, t such that

gcd(a,b)=sa+tb\gcd(a, b) = sa + tb

These coefficients are found by the extended Euclidean algorithm.


2. Prime Numbers

An integer p>1p > 1 is prime if its only positive divisors are 1 and pp itself. Otherwise n>1n > 1 is composite.

2.1 Fundamental Theorem of Arithmetic

Every integer n>1n > 1 has a unique prime factorisation:

n=p1e1p2e2pkek,p1<p2<<pk prime,ei1n = p_1^{e_1} p_2^{e_2} \cdots p_k^{e_k}, \quad p_1 < p_2 < \cdots < p_k \text{ prime},\quad e_i \geq 1

2.2 Density of Primes — Prime Number Theorem

Let π(x)\pi(x) denote the number of primes x\leq x. Then:

limxπ(x)x/lnx=1\lim_{x\to\infty} \frac{\pi(x)}{x / \ln x} = 1

so primes become increasingly sparse, but there are infinitely many of them (Euclid’s proof).

2.3 Sieve of Eratosthenes

To find all primes up to NN:

  1. List integers 2,3,,N2, 3, \ldots, N.

  2. Start at p=2p = 2; mark all multiples of pp greater than pp as composite.

  3. Move to the next unmarked number and repeat.

  4. Stop when p>Np > \sqrt{N}; all unmarked numbers are prime.

2.4 Special Primes

TypeDefinitionExamples
Mersenne prime2p12^p - 13, 7, 31, 127
Fermat prime22n+12^{2^n} + 13, 5, 17, 257, 65537
Twin primes(p,  p+2)(p,\; p+2) both prime(3,5), (11,13), (17,19)
Sophie Germain primepp and 2p+12p+1 both prime2, 3, 5, 11, 23

3. Modular Arithmetic

For a positive integer mm (the modulus), ab(modm)a \equiv b \pmod{m} (read “aa is congruent to bb modulo mm”) if m(ab)m \mid (a - b).

Congruence behaves like equality with respect to addition and multiplication:

ab(modm)a+cb+c(modm)ab(modm)acbc(modm)\begin{align} a \equiv b \pmod{m} &\Rightarrow a + c \equiv b + c \pmod{m} \\ a \equiv b \pmod{m} &\Rightarrow ac \equiv bc \pmod{m} \end{align}

3.1 Residue Classes

The integers modulo mm form the set Zm={0,1,,m1}\mathbb{Z}_m = \{0, 1, \ldots, m-1\} with operations defined mod mm. Zm\mathbb{Z}_m is a field (every nonzero element has a multiplicative inverse) if and only if mm is prime.

3.2 Fermat’s Little Theorem

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

ap11(modp)a^{p-1} \equiv 1 \pmod{p}

Equivalently for any integer aa: apa(modp)a^p \equiv a \pmod{p}. This is the basis of the Fermat primality test and RSA encryption.

3.3 Euler’s Theorem

For gcd(a,n)=1\gcd(a, n) = 1:

aϕ(n)1(modn)a^{\phi(n)} \equiv 1 \pmod{n}

where ϕ(n)\phi(n) is Euler’s totient function — the count of integers in {1,,n}\{1, \ldots, n\} coprime to nn.

For n=p1e1pkekn = p_1^{e_1} \cdots p_k^{e_k}:

ϕ(n)=npn(11p)\phi(n) = n \prod_{p \mid n}\left(1 - \frac{1}{p}\right)

3.4 Chinese Remainder Theorem (CRT)

If m1,m2,,mkm_1, m_2, \ldots, m_k are pairwise coprime, then for any a1,,aka_1, \ldots, a_k the system

xa1(modm1)xa2(modm2)xak(modmk)\begin{align} x &\equiv a_1 \pmod{m_1} \\ x &\equiv a_2 \pmod{m_2} \\ &\vdots \\ x &\equiv a_k \pmod{m_k} \end{align}

has a unique solution modulo M=m1m2mkM = m_1 m_2 \cdots m_k.


4. Diophantine Equations

A Diophantine equation is a polynomial equation for which integer (or rational) solutions are sought.

4.1 Linear Diophantine Equations

ax+by=cax + by = c has integer solutions if and only if gcd(a,b)c\gcd(a, b) \mid c. If a solution (x0,y0)(x_0, y_0) exists, the general solution is:

x=x0+bdt,y=y0adt,d=gcd(a,b),tZx = x_0 + \frac{b}{d}t, \quad y = y_0 - \frac{a}{d}t, \quad d = \gcd(a, b), \quad t \in \mathbb{Z}

4.2 Pythagorean Triples

All positive integer solutions to a2+b2=c2a^2 + b^2 = c^2 (with a<ba < b, gcd(a,b,c)=1\gcd(a,b,c) = 1) are generated by:

a=m2n2,b=2mn,c=m2+n2a = m^2 - n^2, \quad b = 2mn, \quad c = m^2 + n^2

for integers m>n>0m > n > 0 with gcd(m,n)=1\gcd(m, n) = 1 and m≢n(mod2)m \not\equiv n \pmod{2}.

4.3 Pell’s Equation

x2Dy2=1x^2 - Dy^2 = 1 (where DD is a positive non-square integer) always has infinitely many solutions. The fundamental solution (x1,y1)(x_1, y_1) is found from the continued fraction expansion of D\sqrt{D}.


5. Number-Theoretic Functions

FunctionSymbolDefinition
Euler’s totientϕ(n)\phi(n)#{k:1kn,gcd(k,n)=1}\#\{k : 1 \leq k \leq n,\, \gcd(k,n)=1\}
Divisor countτ(n)\tau(n) or d(n)d(n)Number of positive divisors of nn
Divisor sumσ(n)\sigma(n)Sum of all positive divisors of nn
Möbius functionμ(n)\mu(n)0 if p2np^2 \mid n; (1)k(-1)^k if n=p1pkn = p_1\cdots p_k; 1 if n=1n=1
Liouville functionλ(n)\lambda(n)(1)Ω(n)(-1)^{\Omega(n)} where Ω(n)\Omega(n) = total prime factors with multiplicity

All these functions are multiplicative: if gcd(a,b)=1\gcd(a,b)=1 then f(ab)=f(a)f(b)f(ab) = f(a)f(b).


6. Continued Fractions

Any real number xx can be expressed as a continued fraction:

x=a0+1a1+1a2+1a3+x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cdots}}}

denoted [a0;a1,a2,a3,][a_0; a_1, a_2, a_3, \ldots], where the aia_i are positive integers for i1i \geq 1.

  • Rational numbers have finite continued fractions.

  • Quadratic irrationals (like D\sqrt{D}) have infinite periodic continued fractions.

  • Transcendental numbers like e=[2;1,2,1,1,4,1,1,6,]e = [2; 1, 2, 1, 1, 4, 1, 1, 6, \ldots] have no periodic pattern.

The partial quotients [a0;a1,,ak]=pk/qk[a_0; a_1, \ldots, a_k] = p_k/q_k are called convergents and provide the best rational approximations to xx.


7. Rational and Irrational Numbers

A rational number can be written as p/qp/q with p,qZp, q \in \mathbb{Z}, q0q \neq 0. Their decimal expansions are terminating or eventually repeating.

An irrational number cannot be expressed as a ratio of integers. Famous examples:

  • 2\sqrt{2} — proved irrational by Pythagoras; p\sqrt{p} is irrational for every prime pp

  • π3.14159\pi \approx 3.14159\ldots — also transcendental (not a root of any polynomial with integer coefficients)

  • e2.71828e \approx 2.71828\ldots — transcendental (Hermite, 1873)

The set of real numbers is uncountable (Cantor’s diagonal argument), while the rationals are countable.


8. Cryptographic Applications

Number theory provides the mathematical foundation for public-key cryptography.

RSA Encryption (sketch)

  1. Choose large primes p,qp, q and set n=pqn = pq.

  2. Compute ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1).

  3. Choose public exponent ee with gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1.

  4. Find private exponent dd satisfying ed1(modϕ(n))ed \equiv 1 \pmod{\phi(n)}.

  5. Encrypt: cme(modn)c \equiv m^e \pmod{n}. Decrypt: mcd(modn)m \equiv c^d \pmod{n}.

Security rests on the difficulty of integer factorisation of nn when pp and qq are large.

Diffie–Hellman Key Exchange (sketch)

Based on the discrete logarithm problem: given gg, pp (prime), and gxmodpg^x \bmod p, find xx. This is believed to be computationally hard for large pp.


9. Quadratic Residues

An integer aa is a quadratic residue modulo pp (odd prime, gcd(a,p)=1\gcd(a,p)=1) if the congruence x2a(modp)x^2 \equiv a \pmod{p} has a solution. Otherwise aa is a quadratic non-residue.

9.1 Legendre Symbol

(ap)={1if a is a QR mod p1if a is a QNR mod p0if pa\left(\frac{a}{p}\right) = \begin{cases} 1 & \text{if } a \text{ is a QR mod } p \\ -1 & \text{if } a \text{ is a QNR mod } p \\ 0 & \text{if } p \mid a \end{cases}

Euler’s criterion:

(ap)a(p1)/2(modp)\left(\frac{a}{p}\right) \equiv a^{(p-1)/2} \pmod{p}

9.2 Quadratic Reciprocity

For distinct odd primes pp and qq:

(pq)(qp)=(1)p12q12\left(\frac{p}{q}\right)\left(\frac{q}{p}\right) = (-1)^{\frac{p-1}{2}\cdot\frac{q-1}{2}}

Supplementary laws:

(1p)=(1)(p1)/2(2p)=(1)(p21)/8\begin{align} \left(\frac{-1}{p}\right) &= (-1)^{(p-1)/2} \\ \left(\frac{2}{p}\right) &= (-1)^{(p^2-1)/8} \end{align}

Quadratic reciprocity, first proved by Gauss, is often called the “golden theorem” of number theory. It allows efficient computation of the Legendre symbol.

9.3 Jacobi Symbol

The Jacobi symbol (an)\left(\frac{a}{n}\right) generalises the Legendre symbol to composite odd n=p1e1pkekn = p_1^{e_1}\cdots p_k^{e_k}:

(an)=i=1k(api)ei\left(\frac{a}{n}\right) = \prod_{i=1}^k \left(\frac{a}{p_i}\right)^{e_i}

It satisfies the same reciprocity law and is efficiently computable without factoring nn.


10. Primitive Roots and Discrete Logarithms

10.1 Order

The order of aa modulo nn (with gcd(a,n)=1\gcd(a,n)=1) is the smallest positive integer kk such that ak1(modn)a^k \equiv 1 \pmod{n}. By Euler’s theorem, ordn(a)ϕ(n)\operatorname{ord}_n(a) \mid \phi(n).

10.2 Primitive Roots

An integer gg is a primitive root modulo nn if ordn(g)=ϕ(n)\operatorname{ord}_n(g) = \phi(n). Primitive roots exist for n=1,2,4,pk,2pkn = 1, 2, 4, p^k, 2p^k (where pp is an odd prime and k1k \geq 1).

When a primitive root gg exists, every integer coprime to nn can be written as gjmodng^j \bmod n for some jj. This is the discrete logarithm of aa to base gg modulo nn:

loggaj(modϕ(n))where gja(modn)\log_g a \equiv j \pmod{\phi(n)} \quad \text{where } g^j \equiv a \pmod{n}

10.3 Index Calculus

Computing discrete logarithms is believed to be hard in general. The index calculus method is the most practical attack for Zp\mathbb{Z}_p^*:

  1. Choose a factor base of small primes

  2. Collect relations gripjeij(modp)g^{r_i} \equiv \prod p_j^{e_{ij}} \pmod{p}

  3. Solve a linear system modulo p1p-1 to find loggpj\log_g p_j

  4. Express logga\log_g a in terms of the factor base


11. Algebraic Integers and Gaussian Integers

11.1 Gaussian Integers Z[i]\mathbb{Z}[i]

The ring Z[i]={a+bi:a,bZ}\mathbb{Z}[i] = \{a + bi : a, b \in \mathbb{Z}\} extends integer arithmetic to the complex plane.

Norm: N(a+bi)=a2+b2N(a + bi) = a^2 + b^2. The norm is multiplicative: N(αβ)=N(α)N(β)N(\alpha\beta) = N(\alpha)N(\beta).

Units: ±1,±i\pm 1, \pm i (elements with N=1N = 1).

11.2 Primes in Z[i]\mathbb{Z}[i]

A rational prime pp factors in Z[i]\mathbb{Z}[i] according to pmod4p \bmod 4:

pmod4p \bmod 4FactorisationExample
p=2p = 22=i(1+i)22 = -i(1+i)^2 (ramifies)2=i(1+i)22 = -i(1+i)^2
p1(mod4)p \equiv 1 \pmod{4}p=ππˉp = \pi\bar{\pi} (splits)5=(2+i)(2i)5 = (2+i)(2-i)
p3(mod4)p \equiv 3 \pmod{4}pp stays prime (inert)3,7,11,3, 7, 11, \ldots

Fermat’s two-square theorem: A prime pp is a sum of two squares (p=a2+b2p = a^2 + b^2) if and only if p=2p = 2 or p1(mod4)p \equiv 1 \pmod{4}.

11.3 Sum of Squares

Lagrange’s four-square theorem: Every positive integer can be written as the sum of four squares:

n=a2+b2+c2+d2,a,b,c,dZ0n = a^2 + b^2 + c^2 + d^2, \quad a, b, c, d \in \mathbb{Z}_{\geq 0}

12. Perfect Numbers and Mersenne Primes

A positive integer nn is perfect if σ(n)=2n\sigma(n) = 2n (it equals the sum of its proper divisors).

Euclid–Euler theorem: An even number is perfect if and only if it has the form:

n=2p1(2p1)where 2p1 is a Mersenne primen = 2^{p-1}(2^p - 1) \quad \text{where } 2^p - 1 \text{ is a Mersenne prime}

Known Mersenne primes correspond to p=2,3,5,7,13,17,19,31,61,89,107,127,p = 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, \ldots (52 known as of 2025).

Whether any odd perfect numbers exist is one of the oldest unsolved problems in mathematics.


13. Open Problems

Number theory is rich with unsolved conjectures:

ConjectureStatement
Goldbach’s conjectureEvery even integer >2> 2 is the sum of two primes
Twin prime conjectureThere are infinitely many pairs (p,  p+2)(p,\; p+2) of primes
Collatz conjectureThe sequence nn/2n \mapsto n/2 (even) or 3n+13n+1 (odd) always reaches 1
Riemann hypothesisAll non-trivial zeros of ζ(s)\zeta(s) have Re(s)=1/2\operatorname{Re}(s) = 1/2
abc conjectureFor coprime a+b=ca+b=c, the radical rad(abc)\operatorname{rad}(abc) is “usually” not much smaller than cc