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.

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:

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.

This is a placeholder for Number Theory content.