Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Primes and factorisation

Every whole number greater than 1 can be broken into primes, and the real question is whether it can be broken in only one way.

The previous lesson ran Euclid's algorithm backwards to get Bézout's identity: for integers a and b, not both zero, there are integers x and y with ax+by=gcd(a,b). This lesson proves Euclid's lemma from Bézout, uses it to prove that factorisation into primes is unique, then turns to finding primes and counting them.

Primes, and why every number has one

An integer p>1 is prime if its only positive divisors are 1 and p, and an integer n>1 that is not prime is composite, a product n=ab with 1<a,b<n. The number 1 is neither: if it counted as prime, 6=2×3=1×2×3 would already be two factorisations.

Every integer n>1 has a prime divisor, because its smallest divisor d>1 is prime: a divisor c of d with 1<c<d would divide n too, contradicting the choice of d. So the least divisor of 91 above 1 is 7, which is prime, and 91=7×13.

That fact carries Euclid's proof that the primes never run out, recalled here from Proof and Logic rather than taught again: for any finite list of primes, their product plus 1 leaves remainder 1 on division by each, so its prime divisor is missing from the list. The proof, in Book IX of Euclid's Elements around 300 BC, says nothing about how the primes are spread out, a question the end of this lesson takes up.

Euclid's lemma

Euclid's lemma says: if p is prime and p∣ab, then p∣a or p∣b. (Here p∣ab reads "p divides ab".) Composite numbers fail it: 6∣4×9, yet 6 divides neither 4 nor 9, because the factors 2 and 3 of 6 went to different places.

The proof is short. Suppose p∣ab and p does not divide a. The only positive divisors of p are 1 and p, so gcd(p,a)=1. Bézout's identity gives integers x and y with

px+ay=1

Multiply through by b to get pbx+aby=b. The first term is a multiple of p, and so is the second, since p∣ab. So p divides their sum, which is b.

The lemma extends to any number of factors by induction: if p∣a1a2⋯ak, write the product as a1⋅(a2⋯ak), and either p∣a1 or p divides the shorter product. In particular, if a prime p divides a product of primes q1q2⋯qk, it divides some qj, and since the only divisor of qj above 1 is qj itself, p=qj.

Example. Prove that 3 is irrational.

Suppose 3=ab with a and b positive integers sharing no common factor. Squaring gives a2=3b2, so 3∣a⋅a, and Euclid's lemma gives 3∣a. Write a=3c; then 9c2=3b2, so b2=3c2, and the same step gives 3∣b. Now 3 divides both, contradicting lowest terms. The proof for 2 in Proof and Logic used parity at this step; Euclid's lemma works for every prime.

Now you. Prove that 15 is irrational.

Answer

Suppose 15=ab in lowest terms, so a2=15b2. Then 3∣a2, so 3∣a by Euclid's lemma. Writing a=3c gives 9c2=15b2, that is 3c2=5b2. So 3∣5b2, and since 3 does not divide 5 the lemma gives 3∣b2 and then 3∣b. Both a and b are multiples of 3, a contradiction.

The fundamental theorem of arithmetic

Theorem. Every integer n>1 is a product of primes, and this product is unique apart from the order of the factors.

Existence is proved by strong induction, where the hypothesis covers every smaller case at once. The number 2 is prime. Take n>2 and assume every integer from 2 to n-1 is a product of primes. If n is prime there is nothing to do. Otherwise n=ab with 1<a,b<n, both a and b are products of primes by hypothesis, and writing one list after the other expresses n. Ordinary induction would not do, since a and b can be anywhere below n.

Uniqueness is where Euclid's lemma enters. Suppose

p1p2⋯pr=q1q2⋯qs

with every pi and qj prime, and argue by induction on r. The prime p1 divides the right side, so by the extended lemma p1=qj for some j. Reorder so that this one is q1 and cancel it, leaving p2⋯pr=q2⋯qs, a shorter equation of the same kind. By the inductive hypothesis its sides are the same primes in some order, and so were the originals. (When r=1, cancelling leaves 1=q2⋯qs, which forces s=1.)

Collecting repeated primes gives the standard form n=p1e1p2e2⋯pkek with p1<p2<⋯<pk and every exponent at least 1, so 360=23⋅32⋅5. Two numbers are equal exactly when their standard forms agree, which is the sense in which the primes are the atoms of the integers. Euclid had the lemma, but the first clear statement and proof of the whole theorem is in Gauss's Disquisitiones Arithmeticae of 1801.

Why uniqueness is not obvious

Uniqueness can feel too obvious to need proof, since factorising 360 by any route ends at the same primes. To see that it is a real theorem, look at a system where the existence proof works word for word and uniqueness fails.

Take the even numbers 2ℕ={2,4,6,8,…} and call one "prime" there if it is not a product of two even numbers. Such a product is a multiple of 4, so the primes of this system are 2,6,10,14,18,…, the even numbers that are not multiples of 4. The strong induction goes through unchanged, so every even number is a product of these primes. But

36=6×6=2×18

and 2, 6 and 18 are all prime in 2ℕ. What failed is Euclid's lemma: 6 divides 2×18 in this system, yet divides neither 2 nor 18, because 18=6×3 and 3 is not in the system. And the lemma failed because its proof did: 2ℕ has no 1, so no Bézout combination can equal 1.

The same thing happens in systems mathematicians needed. Among the numbers a+b-5 with a and b integers, 6=2×3=(1+-5)(1--5), and none of those four factors splits further. In 1847 Gabriel Lamé announced a proof of Fermat's last theorem that quietly assumed unique factorisation in a system of this kind, and it emerged that Ernst Kummer had already shown in 1844 that it can fail there. For the ordinary integers the theorem holds, and the reason is the division algorithm, through Euclid's algorithm and Bézout.

Computing with factorisations

In standard form, divisibility becomes a comparison of exponents. If n=p1e1⋯pkek, then d∣n exactly when d=p1f1⋯pkfk with 0≤fi≤ei for every i. Conversely, if n=dm, the standard forms of d and m together factorise n, so by uniqueness no prime appears in d more often than in n.

Each divisor is then a choice of exponent for each prime, ei+1 options for pi, so by the product rule the number of positive divisors is

d(n)=(e1+1)(e2+1)⋯(ek+1)

For the gcd and lcm, write both numbers over the same primes, allowing exponent 0. A common divisor may take at most the smaller exponent of each prime and a common multiple needs at least the larger, so the gcd takes minimum exponents and the lcm maximum ones. Since min(e,f)+max(e,f)=e+f, this proves gcd(a,b)⋅lcm(a,b)=ab.

For large numbers Euclid's algorithm is far faster, since nobody knows a fast way to factorise, a gap a later lesson on RSA turns into a lock. By hand, the standard forms show everything at once.

Example. Find the number of divisors of 360, and gcd(360,756) and lcm(360,756).

Factorise: 360=23⋅32⋅5 and 756=22⋅33⋅7. So d(360)=4⋅3⋅2=24. Over the primes 2,3,5,7 the exponents are (3,2,1,0) and (2,3,0,1). Minimums give gcd=22⋅32=36, and maximums give lcm=23⋅33⋅5⋅7=7560. Check: 36×7560=272160=360×756.

Now you. Find the number of divisors of 1008, and gcd(1008,840) and lcm(1008,840).

Answer

1008=24⋅32⋅7 and 840=23⋅3⋅5⋅7. So d(1008)=5⋅3⋅2=30. The exponents over 2,3,5,7 are (4,2,0,1) and (3,1,1,1), giving gcd=23⋅3⋅7=168 and lcm=24⋅32⋅5⋅7=5040, and 168×5040=1008×840.

The sieve of Eratosthenes

To list the primes up to a bound, the method credited to Eratosthenes of Cyrene, the third century BC scholar who also measured the Earth, crosses out composites instead of testing each number. Write out 2,3,…,n. The first number, 2, is prime; cross out its multiples. The next survivor, 3, is prime, since no smaller prime divides it; cross out its multiples. Each number that survives to its turn is prime, and its multiples go.

The sieve can stop early. If n=ab is composite with a≤b, then a2≤ab=n, so a≤n: every composite up to n has a prime factor no bigger than n. Once the primes up to n have been used, every composite is gone. For the same reason the pass for p can start at p2: smaller multiples of p have a smaller prime factor too.

Run to 100, the sieve needs only 2, 3, 5 and 7. The pass for 2 crosses out the 49 even numbers from 4 to 100; the pass for 3 removes 16 new ones, the odd multiples of 3 from 9 to 99; the pass for 5 removes only 25,35,55,65,85,95; and the pass for 7 only 49,77,91. That is 74 composites out of the 99 numbers from 2 to 100, leaving the 25 primes.

Example. Find the primes between 100 and 130.

Since 130<12, only 2,3,5,7,11 are needed. The pass for 2 leaves the fifteen odd numbers 101,103,…,129. The pass for 3 removes 105,111,117,123,129; the pass for 5 removes 115 and 125; the pass for 7 removes 119=7×17; and the pass for 11 removes 121=112. The survivors are 101,103,107,109,113 and 127, six primes.

Now you. Find the primes between 130 and 160.

Answer

160<13, so sieve with 2,3,5,7,11. Of the odd numbers from 131 to 159, the pass for 3 removes 135,141,147,153,159, the pass for 5 removes 145 and 155, the pass for 7 removes 133=7×19, and the pass for 11 removes 143=11×13. The primes are 131,137,139,149,151,157.

How the primes thin out

Up to 100 a quarter of the numbers are prime, from 101 to 160 only twelve of sixty. Write π(x) for the number of primes up to x (a name here, unrelated to 3.14159…). A computer sieve gives the counts below, set against xlnx, with ln the natural logarithm.

xπ(x)x/lnxratio
1002521.71.151
1,000168144.81.161
10,0001,2291,085.71.132
1,000,00078,49872,382.41.084
1,000,000,00050,847,53448,254,942.41.054

The ratio drifts down towards 1, slowly. Carl Friedrich Gauss noticed the pattern in tables of primes around 1792, aged fifteen, and Adrien-Marie Legendre published a similar formula in 1798, but neither could prove it. In 1896 Jacques Hadamard and Charles de la Vallée Poussin, independently, proved the prime number theorem:

limx→∞π(x)x/lnx=1

Both proofs used complex analysis, building on Bernhard Riemann's 1859 work on the zeta function. The theorem has a plain reading: near x, roughly one number in lnx is prime. Near a million that is one in 14, near a billion one in 21. Up to a billion the average gap between primes is 109/50847534≈19.7, just under ln(109)≈20.7, the same slow convergence as in the table.

Locally the primes are irregular. Gaps can be as long as desired: for n≥2 the n-1 numbers n!+2,…,n!+n are all composite, since k divides n!+k for each k from 2 to n. Yet primes two apart, like 101 and 103, keep appearing, and whether they do forever is unknown.

Divisibility is a question about remainders

Everything in this lesson has asked whether one number divides another, and that is a question about a remainder: a∣b exactly when dividing b by a leaves remainder 0. The remainder of a product depends only on the remainders of its factors. Numbers leaving remainders 3 and 5 on division by 7 are 7s+3 and 7t+5, and their product is 7(7st+5s+3t)+15, which leaves the same remainder as 15, namely 1.

In that language Euclid's lemma says: if neither a nor b leaves remainder 0 on division by a prime p, neither does ab. Nonzero remainders multiply without ever producing 0. For a composite divisor this fails, since 2×3 leaves remainder 0 on division by 6: a divisor of a product that divides neither factor, as 6 was in 2ℕ. So the natural setting for divisibility is the remainders themselves, and the next lesson makes them into a number system with its own addition and multiplication, where some elements have inverses and equations can be solved.