Definition
A prime number is an integer whose only positive divisors are 1 and .
A composite number is an integer that is not prime (has divisors other than 1 and itself).
First Few Primes
Note: 1 is neither prime nor composite by convention.
Fundamental Theorem of Arithmetic
Every integer can be written uniquely (up to order) as a product of primes:
where are primes and .
Examples
Properties of Primes
Euclid's Lemma
If is prime and , then or .
Infinitude of Primes
There are infinitely many primes.
Proof (Euclid): Suppose primes are (finite list). Consider . is not divisible by any (leaves remainder 1). So is either prime or has a prime factor not in the list. Contradiction!
Sieve of Eratosthenes
Algorithm to find all primes up to :
- List integers from 2 to
- Start with smallest unmarked number
- Mark all multiples of (except itself)
- Repeat from step 2 until
- Unmarked numbers are prime
Example (up to 30)
Start: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
Cross out multiples of 2: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
Cross out multiples of 3: 9, 15, 21, 27
Cross out multiples of 5: 25
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29
Time Complexity
Prime Factorization
Trial Division
Test divisibility by primes up to :
factor(n):
for p = 2, 3, 5, 7, 11, ... up to √n:
while p divides n:
output p
n = n / p
if n > 1:
output n # remaining prime factor
Using Prime Factorization
For :
Number of divisors:
Sum of divisors:
GCD and LCM:
Primality Testing
Trial Division
Test divisibility by all primes . Time:
Fermat Primality Test
If is prime and , then .
If , then is composite.
Problem: Carmichael numbers pass this test but are composite.
Miller-Rabin Test
Probabilistic test, more reliable than Fermat. Used in practice for large numbers.
AKS Primality Test
Deterministic polynomial-time algorithm (2002). Proves P = NP is not needed for primality testing.
Prime Number Theorem
where = number of primes .
Consequences
- Average gap between consecutive primes near is about
- The -th prime is approximately
Special Types of Primes
| Type | Definition | Examples |
|---|---|---|
| Twin primes | Differ by 2 | (3,5), (5,7), (11,13) |
| Mersenne primes | Form | 3, 7, 31, 127 |
| Fermat primes | Form | 3, 5, 17, 257, 65537 |
| Sophie Germain | and both prime | 2, 3, 5, 11 |
Open Problems
- Twin Prime Conjecture: Infinitely many twin primes
- Goldbach's Conjecture: Every even is sum of two primes
- Are there infinitely many Mersenne primes?