Number theory studies the integers and their properties — divisibility, primes, and modular arithmetic. Gauss called it "the queen of mathematics," and its applications range from cryptography to coding theory.
Divisibility
Definition — Divisibility
An integer adividesb, written a∣b, if there exists an integer k such that b=ak. We say a is a divisor (or factor) of b.
3∣12since12=3⋅45∤13since no integer k satisfies 13=5k
Division Algorithm
For any integers a and b>0, there exist unique integers q (quotient) and r (remainder) with 0≤r<b such that:
a=bq+r
Example: dividing 17 by 5 gives 17=5⋅3+2, so q=3, r=2.
Prime Numbers
Definition — Prime
An integer p>1 is prime if its only positive divisors are 1 and p itself. An integer n>1 that is not prime is composite.
The first few primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, …
There are infinitely many primes — Euclid's proof by contradiction: assume finitely many primes p1,p2,…,pn, then N=p1p2⋯pn+1 is divisible by none of them, contradicting the assumption.
Sieve of Eratosthenes
To find all primes up to n: list integers from 2 to n, then repeatedly cross out multiples of each unmarked number. The survivors are prime. To check primality of n, you only need to test divisors up to n.
GCD and LCM
Definition — GCD
The greatest common divisorgcd(a,b) is the largest positive integer dividing both a and b. If gcd(a,b)=1, the integers are called coprime (or relatively prime).
Definition — LCM
The least common multiplelcm(a,b) is the smallest positive integer divisible by both a and b.
GCD and LCM are related by:
gcd(a,b)⋅lcm(a,b)=∣a⋅b∣
Example: gcd(12,18)=6, lcm(12,18)=36, and 6⋅36=216=12⋅18.
The Euclidean Algorithm
The Euclidean algorithm computes gcd(a,b) efficiently using repeated division. It relies on the observation:
gcd(a,b)=gcd(b,amodb)
Applying this repeatedly until the remainder is zero:
gcd(48,18)=gcd(18,12)=gcd(12,6)=gcd(6,0)=6
The algorithm runs in O(logmin(a,b)) steps — extremely efficient even for very large integers. It is the foundation of RSA and other public-key cryptosystems.
Modular Arithmetic
Definition — Congruence
Integers a and b are congruent modulon, written a≡b(modn), if n∣(a−b).
17≡2(mod5)since 5∣(17−2)
Congruence is an equivalence relation. Arithmetic operations respect it:
a≡b(modn) and c≡d(modn)⇒
a+c≡b+d(modn),ac≡bd(modn)
Modular arithmetic is the mathematics of clocks: on a 12-hour clock, 10+5=3 because 15≡3(mod12).
Fermat's Little Theorem
Theorem — Fermat's Little Theorem
If p is prime and gcd(a,p)=1, then:
ap−1≡1(modp)
Equivalently, for any integer a: ap≡a(modp).
This theorem is the cornerstone of RSA encryption. It also gives a fast way to compute modular inverses: since ap−1≡1, the inverse of a modulo p is ap−2modp.
Example: p=7,a=3. Then 36=729=7⋅104+1, so 36≡1(mod7). ✓
Fundamental Theorem of Arithmetic
Theorem — Fundamental Theorem of Arithmetic
Every integer n>1 can be written as a product of primes in exactly one way, up to ordering:
n=p1e1p2e2⋯pkek
where p1<p2<⋯<pk are primes and ei≥1.
360=23⋅32⋅511001=7⋅11⋅13
This uniqueness is what makes primes the "atoms" of number theory. From the prime factorizations of a and b, one can directly read off gcd and lcm: take the minimum (or maximum) exponent for each prime.