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 and with , we say divides (written ) if there exists an integer such that .
1.1 Division Algorithm¶
For any integers and , there exist unique integers (quotient) and (remainder) with such that:
1.2 Greatest Common Divisor (GCD)¶
The GCD of two integers (not both zero) is the largest positive integer dividing both.
Euclidean algorithm — the most efficient classical method:
Least Common Multiple:
Bézout’s identity: There always exist integers such that
These coefficients are found by the extended Euclidean algorithm.
2. Prime Numbers¶
An integer is prime if its only positive divisors are 1 and itself. Otherwise is composite.
2.1 Fundamental Theorem of Arithmetic¶
Every integer has a unique prime factorisation:
2.2 Density of Primes — Prime Number Theorem¶
Let denote the number of primes . Then:
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 :
List integers .
Start at ; mark all multiples of greater than as composite.
Move to the next unmarked number and repeat.
Stop when ; all unmarked numbers are prime.
2.4 Special Primes¶
| Type | Definition | Examples |
|---|---|---|
| Mersenne prime | 3, 7, 31, 127 | |
| Fermat prime | 3, 5, 17, 257, 65537 | |
| Twin primes | both prime | (3,5), (11,13), (17,19) |
| Sophie Germain prime | and both prime | 2, 3, 5, 11, 23 |
3. Modular Arithmetic¶
For a positive integer (the modulus), (read “ is congruent to modulo ”) if .
Congruence behaves like equality with respect to addition and multiplication:
3.1 Residue Classes¶
The integers modulo form the set with operations defined mod . is a field (every nonzero element has a multiplicative inverse) if and only if is prime.
3.2 Fermat’s Little Theorem¶
If is prime and :
Equivalently for any integer : . This is the basis of the Fermat primality test and RSA encryption.
3.3 Euler’s Theorem¶
For :
where is Euler’s totient function — the count of integers in coprime to .
For :
3.4 Chinese Remainder Theorem (CRT)¶
If are pairwise coprime, then for any the system
has a unique solution modulo .
4. Diophantine Equations¶
A Diophantine equation is a polynomial equation for which integer (or rational) solutions are sought.
4.1 Linear Diophantine Equations¶
has integer solutions if and only if . If a solution exists, the general solution is:
4.2 Pythagorean Triples¶
All positive integer solutions to (with , ) are generated by:
for integers with and .
4.3 Pell’s Equation¶
(where is a positive non-square integer) always has infinitely many solutions. The fundamental solution is found from the continued fraction expansion of .
5. Number-Theoretic Functions¶
| Function | Symbol | Definition |
|---|---|---|
| Euler’s totient | ||
| Divisor count | or | Number of positive divisors of |
| Divisor sum | Sum of all positive divisors of | |
| Möbius function | 0 if ; if ; 1 if | |
| Liouville function | where = total prime factors with multiplicity |
All these functions are multiplicative: if then .
6. Continued Fractions¶
Any real number can be expressed as a continued fraction:
denoted , where the are positive integers for .
Rational numbers have finite continued fractions.
Quadratic irrationals (like ) have infinite periodic continued fractions.
Transcendental numbers like have no periodic pattern.
The partial quotients are called convergents and provide the best rational approximations to .
7. Rational and Irrational Numbers¶
A rational number can be written as with , . Their decimal expansions are terminating or eventually repeating.
An irrational number cannot be expressed as a ratio of integers. Famous examples:
— proved irrational by Pythagoras; is irrational for every prime
— also transcendental (not a root of any polynomial with integer coefficients)
— 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)¶
Choose large primes and set .
Compute .
Choose public exponent with .
Find private exponent satisfying .
Encrypt: . Decrypt: .
Security rests on the difficulty of integer factorisation of when and are large.
Diffie–Hellman Key Exchange (sketch)¶
Based on the discrete logarithm problem: given , (prime), and , find . This is believed to be computationally hard for large .
9. Quadratic Residues¶
An integer is a quadratic residue modulo (odd prime, ) if the congruence has a solution. Otherwise is a quadratic non-residue.
9.1 Legendre Symbol¶
Euler’s criterion:
9.2 Quadratic Reciprocity¶
For distinct odd primes and :
Supplementary laws:
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 generalises the Legendre symbol to composite odd :
It satisfies the same reciprocity law and is efficiently computable without factoring .
10. Primitive Roots and Discrete Logarithms¶
10.1 Order¶
The order of modulo (with ) is the smallest positive integer such that . By Euler’s theorem, .
10.2 Primitive Roots¶
An integer is a primitive root modulo if . Primitive roots exist for (where is an odd prime and ).
When a primitive root exists, every integer coprime to can be written as for some . This is the discrete logarithm of to base modulo :
10.3 Index Calculus¶
Computing discrete logarithms is believed to be hard in general. The index calculus method is the most practical attack for :
Choose a factor base of small primes
Collect relations
Solve a linear system modulo to find
Express in terms of the factor base
11. Algebraic Integers and Gaussian Integers¶
11.1 Gaussian Integers ¶
The ring extends integer arithmetic to the complex plane.
Norm: . The norm is multiplicative: .
Units: (elements with ).
11.2 Primes in ¶
A rational prime factors in according to :
| Factorisation | Example | |
|---|---|---|
| (ramifies) | ||
| (splits) | ||
| stays prime (inert) |
Fermat’s two-square theorem: A prime is a sum of two squares () if and only if or .
11.3 Sum of Squares¶
Lagrange’s four-square theorem: Every positive integer can be written as the sum of four squares:
12. Perfect Numbers and Mersenne Primes¶
A positive integer is perfect if (it equals the sum of its proper divisors).
Euclid–Euler theorem: An even number is perfect if and only if it has the form:
Known Mersenne primes correspond to (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:
| Conjecture | Statement |
|---|---|
| Goldbach’s conjecture | Every even integer is the sum of two primes |
| Twin prime conjecture | There are infinitely many pairs of primes |
| Collatz conjecture | The sequence (even) or (odd) always reaches 1 |
| Riemann hypothesis | All non-trivial zeros of have |
| abc conjecture | For coprime , the radical is “usually” not much smaller than |