An integer p > 1 is said to be prime if its only positive divisors are 1 and p. Thus 2, 3, 5, 7, 11, 13, 17, 19, 23 are all prime. A number n > 1 that is not prime is said to be composite.
There is an algorithm for finding all primes less than n. Start by listing the integers from 2 to n. Cross out all proper multiples ( > 2) of 2. Find the first surviving number after 2, which will, of course, be 3. Cross out all proper multiples of 3. Then the next survivor is prime. Cross out all of its proper multiples. Continue until you reach a survivor greater than the square root of n. Then all surviving numbers are prime.
We illustrate the algorithm for n = 40. First delete multiples of 2:2 3Now continue by crossing out multiples of 3:45678910111213141516171819202122232425262728293031323334353637383940
2 3Now cross out proper multiples of 5. Note that we start with 5*5, since all smaller multiples of 5 have already been crossed out.45678910111213141516171819202122232425262728293031323334353637383940
2 3Since 7*7 is greater than our limit of 40, we can now quit.45678910111213141516171819202122232425262728293031323334353637383940
This algorithm is called the sieve of Eratosthenes
Every n > 1 has a unique factorization into primes. For example, 16335 = 33*51*112.
In general, we can write

Theorem. If p is a prime and p | ab, then either p | a or p | b.
Proof. If p does not divide a, then gcd(p, a) = 1. Then p | b by a theorem in the preceding note.
If
,
.This is known as Euclid's Theorem. For proof, suppose by way of contradiction that there are only finitely many primes p1, p2, ..., pk. Consider the number n=p1p2...pk+1. If you divide n by any pi, then you get remainder 1. But n must have some prime factor. So we reach a contradiction; there must be a prime that we did not list.
Factoring is hard in the computer science sense; as far as is known, it takes exponential time. By way of illustration, consider the Fermat numbers Fn=22^n+1. The first few are F0=3, F1=5, F2=17, F3=257, F4=65537, and F5=232+1=4294967297. Fermat conjectured that all of the Fermat numbers are prime, but Euler found the factor 641 of F4.
In 1905, Morehead and Western, working independently, proved that F7 = 2128+1 = 340282366920938463463374607431768211457 is not prime. They did not factor it. Factorization had to wait until 1971, when Brillhart and Morrison
used a Control Data supercomputer to find the factorization
F7=59649589127497217*5704689200685129054721.
Both factors are prime.
F14, a number with 4933 digits, is known to be composite, but none of its factors has been found. For more information on the current status of Fermat numbers, see a compilation by W. Keller.
The difficulty of factoring large integers is basic to the most popular algorithms for secure transfer of data in use today.