Contents / Number Theory / Divisors & Primes
Chapter 1
Divisors & Primes
Divisibility and its algebra; the division algorithm with existence and uniqueness; tau and sigma from the factorisation, with odd tau characterising the squares; Euclid's infinitude of primes and a second proof via Fermat numbers; the sieve proved correct and the sqrt(n) bound; the Euclidean algorithm, Bezout, Euclid's lemma, and the Fundamental Theorem of Arithmetic with existence and uniqueness kept separate; and Lame's bound with its Fibonacci worst case.
Introduction
Multiplication takes two integers and returns one. Reversing it — given , which pairs multiply to give it? — is the whole of this chapter, and it is very much harder than the forward direction. The forward direction is a single algorithm you learned at seven. The reverse direction supports an industry: the security of most public-key cryptography rests on the belief that recovering the two factors of a -bit product is infeasible, while forming the product takes microseconds.
That asymmetry is not the only surprise. The atoms of multiplication, the primes, are simultaneously rigid and unruly. Rigid, because every integer above breaks into primes in exactly one way — the Fundamental Theorem of Arithmetic, which is so familiar that its content is easy to miss and whose proof genuinely needs an idea. Unruly, because no formula produces the primes, they thin out but never stop, and the gaps between them can be made as large as you please while pairs of them apparently stay two apart forever.
The chapter is built around one algorithm and one theorem. The algorithm is division with remainder, and everything in the second half is a consequence of iterating it: the Euclidean algorithm, Bézout's identity, Euclid's lemma, and through Euclid's lemma the uniqueness half of the Fundamental Theorem. The theorem is the Fundamental Theorem itself, whose two halves — existence and uniqueness — are proved separately, by completely different arguments, and are kept visibly apart here because conflating them is the classic way to produce a proof that proves nothing.
Along the way we count divisors, sum them, sieve for primes, certify primality with a bound, and finish with Lamé's theorem: the Euclidean algorithm's worst input is a pair of consecutive Fibonacci numbers, and consequently the algorithm never takes more than about five times the number of decimal digits of the smaller argument. Throughout, integer means element of , and . The one axiom we lean on repeatedly is well-ordering: every nonempty set of non-negative integers has a least element.
1.1Divisibility: the definition and its immediate consequences
Divisibility is a relation between integers, defined by an existence statement. It is worth noticing at the outset that the definition never mentions division, remainders or fractions — only multiplication. That is what makes it usable inside , where division is not available.
Definition 1.1 (Divisibility). Let and be integers. We say divides , written , if there exists an integer with
We then call a divisor or factor of , and a multiple of . If no such exists we write .
Intuition. says that objects can be laid out in rows of with nothing left over. The quotient is the number of rows. Negative and zero cases are the same statement read literally: for every because , and only for because is always .
The asymmetry of trips people up, so state it once. Every integer divides ; divides nothing except . This is not a convention adopted for convenience — it is forced by the definition, and any rule below that would fail at carries the hypothesis explicitly.
Proposition 1.2 (Elementary consequences of the definition). For all integers :
- and and .
- If and , then .
- If and , then .
Proof. For (1), take , and respectively in the definition.
For (2), write . Since , neither nor is zero, so and .
For (3), if either of is then the other is too, by the remark that divides only , and the conclusion holds. Otherwise both are nonzero and (2) applies in both directions, giving and , hence , which for integers means .∎
Part (2) is the workhorse of every finiteness argument in the chapter: the divisors of a nonzero all lie in , so there are finitely many of them and a search for them terminates. Part (3) says divisibility is antisymmetric up to sign, which is why it is a partial order on rather than on .
Example 1.3 (Reading the definition off a product). Decide whether , and whether .
Solution.
- For the first, look for an integer with . Since , such a exists and .
- For the second, , and is an integer, so . The sign of the quotient is irrelevant: the definition asks only that be an integer.
Pitfall. and are different kinds of object. The first is a statement, true or false; the second is a number, and only meaningful when . Writing " " confuses the two. The vertical bar is not a slash.
1.2Proper divisors and the classification of numbers
Once we can list the divisors of , we can add them up, and comparing that sum with itself produces the oldest classification in arithmetic.
Definition 1.4 (Proper divisor). A proper divisor of a positive integer is a positive divisor of with . Thus itself is excluded, while is included whenever .
Definition 1.5 (Divisor functions). For a positive integer write
the number of divisors and the sum of divisors. The sum of the proper divisors is then .
Definition 1.6 (Perfect, abundant, deficient). A positive integer is perfect if , equivalently ; abundant if ; and deficient if .
Intuition. Think of as a budget and its proper divisors as the pieces you are allowed to spend. A perfect number spends its budget exactly: . An abundant number overshoots, a deficient one falls short. Deficiency is overwhelmingly the common case — every prime is deficient, with — and perfection is rare enough that only perfect numbers are known.
Example 1.7 (Classifying 28 and 12). Classify and as perfect, abundant or deficient.
Solution.
- The positive divisors of are , so and . Since , the number is perfect.
- The positive divisors of are , so and . Hence is abundant.
- For contrast, and , so is deficient.
Remark. Euclid proved that if is prime then is perfect, and Euler proved that every even perfect number has that shape. Whether an odd perfect number exists is open after more than two thousand years; it is known that one would have to exceed .
1.3Transitivity and linearity
Two rules carry almost all the weight in divisibility arguments. The first says the relation composes; the second says the set of multiples of is closed under integer combinations. Nearly every "show that divides..." exercise is one of these two applied once or twice.
Theorem 1.8 (Transitivity of divisibility). If and , then .
Proof. By hypothesis there are integers and with and . Substituting the first into the second,
Since is an integer, the definition of divisibility is satisfied with quotient .∎
Theorem 1.9 (Linearity of divisibility). If and , then for all integers and ,
Proof. Write and with . Then
and is an integer, so divides .∎
An expression with is called an integer linear combination of and . The theorem Linearity of divisibility therefore reads: any common divisor of and divides every linear combination of them. That single sentence is the seed of the Euclidean algorithm, of Bézout's identity, and of the contradiction in Euclid's proof that the primes do not stop.
Corollary 1.10 (Divisors of a difference). If and , then .
Proof. Apply the theorem Linearity of divisibility to the two multiples and with coefficients and : divides .∎
Example 1.11 (A divisibility chain). Given that and for some positive integer , what are the possible values of , and what does the theorem Linearity of divisibility predict about ?
Solution.
- Linearity with , gives .
- So every common divisor of and divides , leaving .
- All three do occur, since each divide both and . Notice how the argument found the answer without listing the divisors of either number.
Example 1.12 (Transitivity applied twice). Show that if and and , then , and give the largest such when .
Solution.
- Two applications of the theorem Transitivity of divisibility: from and we get , and from and we get .
- With the constraint already forces , and works since .
- Largest value: .
1.4Counting and summing the divisors
If is given in factored form the divisors can be counted without being listed, and the counting argument is a clean piece of combinatorics. It presumes the Fundamental Theorem of Arithmetic, proved later in this chapter in Existence of a prime factorisation and Uniqueness of the prime factorisation; nothing below is circular, since those proofs do not use anything from this section.
Theorem 1.13 (The divisor-counting formula). Let have prime factorisation
with distinct primes and exponents . Then
Proof. We exhibit a bijection between the positive divisors of and the tuples of integers with .
If with , then , and the second factor is an integer, so . This maps tuples to divisors.
Conversely let be a positive divisor, say . Factor and into primes; concatenating those two factorisations gives a prime factorisation of , which by uniqueness must be the one we started with. Hence every prime occurring in is some , and its exponent in is at most its exponent in . So has the stated form, and the map is onto.
It is injective because uniqueness of factorisation says two distinct exponent tuples give distinct integers. Finally, the number of tuples is , since is chosen independently from a set of values.∎
Intuition. Building a divisor is shopping from shelves. Shelf holds the powers — that is options — and you must take exactly one item from each shelf. Multiply the options.
Theorem 1.14 (The divisor-sum formula). With as in the theorem The divisor-counting formula,
Proof. By the bijection established in the proof of The divisor-counting formula, summing over divisors is summing over exponent tuples:
where the second equality is the distributive law: expanding the product of the sums produces each tuple's term exactly once. Each inner sum is a finite geometric series with ratio , whose value is .∎
Corollary 1.15 (Odd divisor count characterises squares). A positive integer has an odd number of positive divisors if and only if is a perfect square.
Proof. By the theorem The divisor-counting formula, is odd exactly when every factor is odd, that is when every exponent is even. Writing gives , a square. Conversely a square has all exponents even, since squaring doubles every exponent. For both sides hold, as .∎
Intuition. Divisors pair off as , which consumes them two at a time. The only way a divisor can fail to have a distinct partner is , that is — which exists exactly when is a square. That is why has the odd count and the even count .
Example 1.16 (Divisors of 360). Compute and .
Solution.
- Factor: .
- By The divisor-counting formula, .
- By The divisor-sum formula, .
- Since , the number is abundant.
Example 1.17 (Designing a number with a prescribed divisor count). Find the smallest positive integer with exactly divisors.
Solution.
- We need exponents with . The possible multisets of are , , , and — the last two coincide.
- To minimise the integer, assign the largest exponents to the smallest primes. The candidates are , , , and .
- The smallest is , and indeed .
1.5Primes: the atoms of multiplication
Definition 1.18 (Prime and composite). An integer is prime if its only positive divisors are and . An integer that is not prime is composite; equivalently for some integers with . The integer is neither prime nor composite.
Remark. Excluding is not squeamishness. If counted as prime then would have infinitely many prime factorisations and the Fundamental Theorem of Arithmetic would be false as stated. The convention is chosen to make uniqueness true.
Lemma 1.19 (Every integer above 1 has a prime divisor). Every integer has at least one prime divisor.
Proof. Consider the set of divisors of that are greater than . It is nonempty, since , and consists of positive integers, so by well-ordering it has a least element .
Suppose were composite. Then with , and with gives by the theorem Transitivity of divisibility. So and , contradicting minimality of . Hence is prime, and .∎
This is the first of many arguments in the chapter that run on well-ordering. The pattern — take the least element of a set of positive integers, show that any failure of the desired property would produce a smaller element — recurs in the division algorithm, in Bézout's identity and in the existence half of the Fundamental Theorem.
Example 1.20 (Smallest prime factor by hand). Find the smallest prime factor of .
Solution.
- Test primes in increasing order. is odd, its digit sum is not divisible by , and it does not end in or .
- , so ; , so ; , so .
- , so the smallest prime factor is . (There was no need to test beyond , since — see Trial division stops at the square root.)
1.6Infinitude of the primes
That the primes never stop is the first theorem in mathematics whose proof is a genuine argument rather than a computation, and it has been reproved in dozens of ways. Two are given here: Euclid's, which is a one-line application of linearity, and a second, due to Goldbach, which produces an infinite family of pairwise coprime integers and reads off a distinct prime from each.
Theorem 1.21 (Euclid: there are infinitely many primes). The set of prime numbers is infinite.
Proof. Suppose, for contradiction, that the primes are exactly , a finite list. Put
Then , so by the lemma Every integer above 1 has a prime divisor it has a prime divisor , and must be one of the since the list is all of them. Now divides the product and, by assumption, divides ; so by the corollary Divisors of a difference, divides . But no prime divides , since a prime exceeds and part (2) of Elementary consequences of the definition forbids a divisor of from exceeding . This contradiction shows no finite list can contain every prime.∎
Pitfall. Euclid's argument does not claim that is prime. Taking the first five primes, is prime, but is not. The claim is only that has a prime factor outside the list — which is exactly what is needed.
Definition 1.22 (Fermat numbers). The -th Fermat number is for . The first few are , , , , .
Lemma 1.23 (Fermat numbers telescope). For every ,
Proof. Induct on . For the left side is and the right side is .
Assume the identity for . Then
using . This is the identity for .∎
Theorem 1.24 (Goldbach: a second proof of infinitude). Distinct Fermat numbers have no common divisor greater than . Consequently there are infinitely many primes.
Proof. Let and let divide both and . By the lemma Fermat numbers telescope, divides the product , which equals ; hence . Since also , the corollary Divisors of a difference gives , so . But every Fermat number is odd, being more than a power of , so and therefore .
Now for each choose, by the lemma Every integer above 1 has a prime divisor, a prime . If for some then that prime would be a common divisor of and exceeding , which we have just excluded. So is injective and produces infinitely many distinct primes.∎
Remark. Euclid's proof is non-constructive about which new prime appears; Goldbach's produces an explicit infinite list of pairwise coprime numbers, one prime harvested from each. A third classical proof, Euler's, observes that diverges, which says far more: the primes are not merely infinite but reasonably dense.
Theorem 1.25 (Arbitrarily large prime gaps). For every integer there exist consecutive composite integers.
Proof. Consider the integers
For each with , the integer divides because is one of the factors in that product, and divides itself; so by the theorem Linearity of divisibility, . Since , this exhibits a divisor strictly between and the number, so is composite. There are such , and the integers are consecutive.∎
Remark. The primes thin out in a precise sense. Writing for the number of primes not exceeding , the Prime Number Theorem asserts , meaning the ratio tends to . Its proof requires complex analysis and belongs to Analytic Number Theory; the figure below shows how good the approximation already is by . Yet the gaps theorem above shows that within this smooth average behaviour there are deserts of any prescribed length, and the twin prime conjecture asserts that there are also infinitely many gaps of size exactly . Average regularity and local irregularity coexist.
1.7Sieving and primality testing
To decide whether one number is prime, divide by candidate factors. To find every prime up to a bound, do something much better: cross out multiples. Both procedures rest on the same observation about square roots.
Proposition 1.27 (Trial division stops at the square root). If is composite, then has a prime divisor with . Consequently, if no prime divides , then is prime.
Proof. Since is composite, write with . If both factors exceeded we would get , which is absurd; so . By the lemma Every integer above 1 has a prime divisor, has a prime divisor , and . Transitivity of divisibility gives .
The second sentence is the contrapositive: if no prime up to divides , then cannot be composite, and being greater than it is prime.∎
Intuition. Divisors come in pairs and straddling — if one is above, the other is below. So a search below misses nothing. The saving is enormous: certifying prime needs trial divisions by the primes up to , of which there are eleven, not by the numbers below it.
Method 1.28 (Sieve of Eratosthenes). To list every prime up to :
- Write the integers , all initially unmarked.
- Let be the smallest unmarked number not yet used as a sieving prime.
- Mark every multiple up to as composite.
- Repeat from step 2 while .
- The unmarked numbers are exactly the primes up to .
Theorem 1.29 (Correctness of the sieve). After the procedure Sieve of Eratosthenes halts, an integer with is unmarked if and only if is prime.
Proof. Suppose is prime. A number gets marked only as a multiple with , so a marked number has a divisor with , hence is composite. A prime is therefore never marked.
Conversely suppose is composite. By the proposition Trial division stops at the square root, has a prime divisor ; take least such. Write . Every prime factor of is at least by minimality of , and , so and therefore . Thus lies in the range that step 3 marks. It remains to check that the loop actually reaches : the loop runs while , and , so it does. Hence is marked.
Starting step 3 at rather than at loses nothing, precisely because any smaller multiple with has a prime factor of below and was already marked in an earlier pass.∎
Example 1.31 (Sieving up to 30). Carry out the procedure Sieve of Eratosthenes for and state how many sieving passes are needed.
Solution.
- Since the loop runs while , and , only the primes are used as sieving primes: three passes.
- Pass marks . Pass marks (the even multiples already went). Pass marks alone.
- Unmarked: — ten primes, so .
Example 1.32 (Certifying a prime by trial division). How many trial divisions does Trial division stops at the square root require to certify that is prime?
Solution.
- , so we test the primes : these are .
- None divides : it is odd, digit sum , does not end in or , and .
- Six trial divisions suffice, and is prime.
1.8A first look at factorisation
Before the theorem is stated in full, it pays to factor a few numbers by hand and watch what happens: repeatedly strip off the smallest prime factor. The lemma below is what guarantees the procedure never gets stuck, and the observation that the answer never depends on the order of stripping is the uniqueness claim in embryo.
Lemma 1.33 (The least divisor above 1 is prime). If and is the smallest divisor of exceeding , then is prime and unless itself is prime.
Proof. Primality of is exactly the argument in Every integer above 1 has a prime divisor: a composite would have a divisor strictly between and which, by transitivity, also divides , contradicting minimality.
For the bound, suppose is not prime. Then , and is an integer greater than , so has a divisor above , hence by minimality of among divisors of . Multiplying by gives .∎
Example 1.34 (Factorising 180 by repeated stripping). Factor into primes by repeatedly dividing out the smallest prime factor, and check the result against .
Solution.
- , ; is odd, so the powers of stop at .
- , ; so divides and no more.
- is prime, so .
- Check: , and .
Example 1.35 (Order does not matter). Factor by stripping the largest prime factor first, and compare with the usual order.
Solution.
- Largest first: , , then , then giving .
- The multiset collected is , so .
- Smallest first gives , , , , , — the same multiset in a different order. That this always happens is the content of Uniqueness of the prime factorisation.
1.9The division algorithm
Everything remaining in the chapter comes from one statement: you can always divide, provided you accept a remainder, and the quotient and remainder are uniquely determined. It is called an algorithm for historical reasons; as stated it is a theorem, and the proof of existence is the well-ordering argument again.
Theorem 1.36 (Division algorithm). Let and be integers with . Then there exist unique integers and with
Proof. Existence. Consider the set
is nonempty: taking gives , since . So is a nonempty set of non-negative integers and by well-ordering has a least element for some integer . By construction and .
Suppose . Then , so ; but because , contradicting minimality. Hence .
Uniqueness. Suppose with . Subtracting,
The right-hand side satisfies , so , which forces . An integer of absolute value below is zero, so , and then .∎
Corollary 1.37 (Division by a nonzero divisor of either sign). For integers and with there are unique integers with and .
Proof. If this is the theorem Division algorithm. If apply that theorem to and , obtaining with , and set , so . Uniqueness transfers the same way: any representation with divisor gives one with divisor by negating the quotient, and those are unique.∎
Intuition. On the number line, mark the multiples of . They cut into blocks of length , and lies in exactly one block: names the block and names the position inside it. Existence is "the blocks cover everything"; uniqueness is "the blocks do not overlap".
Pitfall. The remainder is always taken non-negative, even when is negative. Dividing by gives and , since ; it does not give . Many programming languages disagree with the theorem here, returning for -17 % 5, so never trust a language's % to implement the division algorithm without checking.
Example 1.38 (Dividing with a negative dividend). Find the and guaranteed by Division algorithm for , .
Solution.
- We need the largest multiple of at or below . Since and , take .
- Then , and indeed .
- So , .
1.10The Euclidean algorithm
Definition 1.39 (Greatest common divisor). For integers not both zero, the greatest common divisor is the largest integer dividing both. It exists because the set of common divisors is nonempty (it contains ) and bounded above by , using part (2) of Elementary consequences of the definition. We set , and call coprime when .
Definition 1.40 (Least common multiple). For nonzero integers , the least common multiple is the smallest positive integer divisible by both. It exists by well-ordering, since is one such multiple.
The naive way to compute is to factor both. That is hopeless for large inputs — factoring is the hard problem — and completely unnecessary, because the following one-line identity lets us shrink the problem instead.
Lemma 1.41 (The gcd is invariant under division). If then .
Proof. It suffices to show that the pairs and have the same set of common divisors; the greatest element of that set is then the same number.
If and , then by the theorem Linearity of divisibility, so is a common divisor of and . Conversely if and then , again by linearity, so is a common divisor of and .∎
Method 1.42 (Euclidean algorithm). To compute with :
- Divide: with .
- If , stop and return .
- Otherwise replace by and go back to step 1.
Theorem 1.43 (Correctness and termination of the Euclidean algorithm). For the procedure Euclidean algorithm halts after finitely many divisions, and the last nonzero remainder is .
Proof. Termination. Write the successive remainders , where is the remainder on dividing by . The theorem Division algorithm guarantees , so the remainders form a strictly decreasing sequence of non-negative integers. No such sequence is infinite — by well-ordering, the set of remainders produced has a least element, and the step after it must yield remainder . Hence the algorithm halts.
Correctness. Set , , and let be the last nonzero remainder, so . Repeated application of the lemma The gcd is invariant under division gives
Finally , since every integer divides and the greatest divisor of is itself. So the returned value is .∎
Example 1.45 (Euclid on 1071 and 462). Compute and count the divisions used.
Solution.
- .
- .
- .
- The last nonzero remainder is , so , found in three divisions. Factoring would have required discovering and — more work for the same answer.
Example 1.46 (A coprime pair). Compute .
Solution.
- .
- .
- ; ; ; .
- Last nonzero remainder , so the two numbers are coprime.
1.11Bézout's identity and the extended algorithm
The Euclidean algorithm computes ; run backwards it does more, expressing that gcd as an integer combination of and . This is the single most useful fact in elementary number theory, and it is what finally pays for Euclid's lemma and hence for uniqueness of factorisation.
Theorem 1.47 (Bézout's identity). Let be integers, not both zero. Then there exist integers with
Proof. We may assume , since changing signs only changes the signs of , and the case is .
Run the Euclidean algorithm, producing , and
with and by Correctness and termination of the Euclidean algorithm.
We prove by strong induction on that each is an integer combination of and . For and this is clear: and . For the step, suppose and . Rearranging the division equation,
which is again an integer combination. Taking gives the claim for .∎
The induction in that proof is an algorithm: carry the pair alongside each remainder and update it by the same recurrence, , and likewise for . That is the extended Euclidean algorithm, and it costs no more divisions than the plain one.
Corollary 1.48 (The gcd is the least positive combination). For not both zero, is the smallest positive integer of the form with . Moreover an integer is of the form if and only if .
Proof. Let and let be the least positive integer of the form , which exists by well-ordering since the set of such positive values is nonempty (it contains ). By the theorem Linearity of divisibility, , so . By Bézout's identity, is itself of that form, so . Hence .
For the second claim, if then by linearity. Conversely if then writing gives .∎
Corollary 1.49 (Common divisors divide the gcd). If and then .
Proof. Write by Bézout's identity and apply the theorem Linearity of divisibility.∎
This is a strengthening worth pausing on. The definition only says the gcd is the largest common divisor; the corollary says it is a multiple of every common divisor — greatest in the divisibility order, not merely in size. That is the property which generalises to rings where "largest" makes no sense.
Theorem 1.50 (Euclid's lemma). If is prime and , then or .
Proof. Suppose . The only positive divisors of are and , so ; it cannot be , since would follow. Hence , and by Bézout's identity there are integers with
Multiply through by :
Now divides outright, and divides because by hypothesis. By the theorem Linearity of divisibility, divides their sum, which is .∎
Pitfall. Primality is essential. , yet and . The step that fails for a composite is : for the gcd is , neither of the two.
Corollary 1.51 (Euclid's lemma for several factors). If a prime divides a product , then for some .
Proof. Induct on . The case is trivial. For write the product as ; by Euclid's lemma either , and we are done, or divides , to which the inductive hypothesis applies.∎
Example 1.52 (Extended Euclid on 240 and 46). Find integers with .
Solution.
- Forward: ; ; ; ; . So .
- Back-substitute: .
- Continue: .
- So , , and a check gives .
Example 1.53 (Solving a linear Diophantine equation). Does have an integer solution? Find one if it does.
Solution.
- By The gcd is the least positive combination, a solution exists exactly when . Here and , so yes.
- Bézout for the gcd: .
- Scale by : , so .
1.12The Fundamental Theorem of Arithmetic: statement
Theorem 1.54 (Fundamental Theorem of Arithmetic). Every integer can be written as a product of primes,
and this representation is unique up to the order of the factors. Collecting equal primes, every has a unique canonical factorisation
The theorem makes two independent claims, and they are proved below in two separate sections because they need entirely different tools. Existence — that a factorisation exists at all — is a induction on size and uses nothing about primes beyond the definition. Uniqueness — that there is only one — is the deep half, and it needs Euclid's lemma, hence Bézout, hence the division algorithm.
Remark. The temptation is to think uniqueness is obvious. It is not, and the standard way to see this is to look at a number system where it fails. In the set of even numbers, closed under multiplication, call an element "irreducible" if it is not a product of two elements of . Then are all irreducible in , and
gives two genuinely different factorisations. Nothing in the existence argument is violated; what fails is Euclid's lemma, since but divides neither nor within . Uniqueness is a theorem about , not a law of thought.
Note. Adopting the convention that the empty product equals lets the theorem include , factored as the product of no primes. This also makes the statement " " consistent with the divisor-counting formula read as an empty product.
1.13Existence of a factorisation
Theorem 1.55 (Existence of a prime factorisation). Every integer is a product of (one or more) primes.
Proof. Strong induction on . Suppose the claim holds for every integer with .
If is prime, it is a product of one prime and there is nothing to prove.
Otherwise is composite, so with and . Both and fall in the range covered by the inductive hypothesis, so and for primes . Concatenating,
a product of primes. By strong induction the claim holds for every .∎
Remark. The same argument can be run as a minimal-counterexample proof, which some find clearer: if some integer above had no prime factorisation, well-ordering would give a least such ; could not be prime, so with both factors smaller and above , and both would then factor by minimality, giving a factorisation of after all. Strong induction and least-counterexample are the same argument in two dresses.
Notice what the existence proof did not use: nothing about Bézout, nothing about Euclid's lemma, and no property of primes except the definition of composite. That is why it also works in the even-numbers system of the remark above, where uniqueness fails — existence is cheap.
Example 1.56 (Existence made explicit). Follow the existence proof on , recording the splits it performs.
Solution.
- is composite: .
- is composite: , and , and .
- Every leaf of this splitting tree is prime, so .
- Each split strictly decreased the numbers involved, which is exactly why the recursion terminates.
1.14Uniqueness of the factorisation
Theorem 1.57 (Uniqueness of the prime factorisation). If
with all and prime, then and the list is a rearrangement of .
Proof. Induct on .
Base case . Then . If the right-hand side has the divisor with , contradicting primality of . So and .
Inductive step. Let and assume the statement for products of primes. The prime divides the left side, hence divides ; by the corollary Euclid's lemma for several factors, for some . Reordering the 's, take . Since is prime its only divisors above are and , and , so .
Cancel this common factor — legitimate because and has no zero divisors — to get
The left side is a product of primes, so the inductive hypothesis gives and a matching of the remaining factors. Restoring completes the matching of the full lists.∎
Intuition. The whole weight sits on the single sentence " divides the product, so it divides one of the factors". Without Euclid's lemma a prime could sneak in as a divisor of a product while dividing no individual factor, and the two factorisations would never be forced to align — which is precisely what happens in the even-numbers system, where divides but neither factor.
Example 1.58 (Uniqueness as a constraint). Given that and has divisors, find .
Solution.
- , so by The divisor-counting formula, .
- Both factors are odd; the factorisations of into two odd factors are , , and their reversals. These give .
- Requiring both exponents positive and leaves and , that is or . Uniqueness of factorisation is what makes the exponent bookkeeping in step 1 valid at all.
1.15gcd and lcm from the factorisations
With uniqueness in hand, both the gcd and the lcm can be read off the exponents. This is the conceptually clean description; the Euclidean algorithm remains the one you actually compute with, because it does not require factoring.
Theorem 1.59 (gcd and lcm by exponents). Let be positive integers and write them over a common set of primes,
Then
Proof. As in the proof of The divisor-counting formula, uniqueness of factorisation says divides if and only if for every . So is a common divisor of and exactly when and for all , that is . The largest such takes throughout, which is the stated formula.
The multiple case is dual: is divisible by exactly when , so a common multiple needs , and the smallest one takes equality.∎
Theorem 1.60 (Product of gcd and lcm). For positive integers and ,
Proof. Fix a prime and compare exponents on both sides. On the left, by the theorem gcd and lcm by exponents, the exponent is . On the right it is . For any two numbers, the smaller plus the larger is the sum of the two, so . The two sides have identical exponents at every prime, and by uniqueness of factorisation two positive integers with the same canonical factorisation are equal.∎
Corollary 1.61 (lcm from the Euclidean algorithm). For positive , , so the lcm is computable without factoring.
Proof. Divide the identity of Product of gcd and lcm by , which is positive and hence nonzero.∎
Pitfall. The identity is a statement about two numbers only. For three it fails: and , but .
Example 1.62 (gcd and lcm two ways). Compute and , first from factorisations and then check with the Euclidean algorithm.
Solution.
- and .
- Exponentwise minima: . Maxima: .
- Euclid: , , , giving as expected.
- Check the product law: .
Example 1.63 (Recovering a number from gcd and lcm). Two positive integers have gcd and lcm , and one of them is . Find the other.
Solution.
- By Product of gcd and lcm, the product of the two numbers is .
- Dividing by the known one: .
- Check: and . The other number is .
1.16How fast is Euclid? Lamé's theorem
The Euclidean algorithm terminates; the practical question is how quickly. The answer, found by Lamé in 1844 and often called the first theorem in computational complexity, is that the worst inputs are consecutive Fibonacci numbers, and that the step count is linear in the number of digits.
Definition 1.64 (Fibonacci numbers). The Fibonacci numbers are defined by and for , giving
Lemma 1.65 (Fibonacci pairs are the slowest). If the Euclidean algorithm applied to performs exactly divisions, then and .
Proof. Induct on . For the algorithm halts at once, so and gives .
Assume the statement for and suppose the run on takes divisions, the first being with . The remaining run is on the pair and takes divisions, so by the inductive hypothesis and . Since and ,
Theorem 1.66 (Lamé's theorem). If and the Euclidean algorithm takes divisions to compute , then is at most five times the number of decimal digits of . The bound is attained by consecutive Fibonacci numbers.
Proof. By the lemma Fibonacci pairs are the slowest, . A standard induction shows for , where : it holds at , and , using .
Hence , so taking base- logarithms, . Now , so
If has decimal digits then , so , that is .
For attainment, run the algorithm on : since with , every quotient is and the remainder sequence is the Fibonacci sequence run backwards, so the number of divisions is as large as the lemma permits.∎
Intuition. Every quotient of is a wasted step: the pair barely shrinks. The Fibonacci recurrence is the extreme case where every quotient is , so the algorithm crawls. Any quotient of or more at least halves the larger argument, which is why typical inputs finish far faster than the bound — on random inputs the expected number of divisions is about .
Example 1.67 (The worst case at five digits). How many divisions does the Euclidean algorithm use on , and how does that compare with Lamé's bound?
Solution.
- ; ; ; ; ; ; ; ; .
- That is nine divisions, every quotient until the last — the Fibonacci signature.
- has digits, so Lamé allows up to divisions. Nine is just under the bound, showing the bound is tight to within one step here.
Example 1.68 (Bounding work before doing it). Before computing, bound the number of divisions the Euclidean algorithm can need for .
Solution.
- The smaller argument has decimal digits.
- By Lamé's theorem the algorithm uses at most divisions.
- In fact it uses far fewer; the bound is a worst-case guarantee, and worst cases are Fibonacci-shaped, which is not.
Summary. The chapter's logical spine, in order of dependence: well-ordering gives the division algorithm; iterating division gives the Euclidean algorithm, which terminates because remainders strictly decrease; running it backwards gives Bézout's identity; Bézout gives Euclid's lemma; Euclid's lemma gives uniqueness in the Fundamental Theorem, whose existence half is a separate and much easier strong induction. On top of the Fundamental Theorem sit the exponent formulas for , , and ; on top of the Euclidean algorithm sits Lamé's bound.
- Confusing with or . The bar is a relation and produces a truth value; the slash is an operation and produces a number. " " is not a sentence.
- Getting the direction of the bar backwards. says three divides twelve. Reading it as "3 divided by 12" reverses every subsequent inference.
- Mishandling zero. Every integer divides ; divides only . In particular , and the bound from Elementary consequences of the definition needs .
- Calling prime. It is a unit, not a prime, and admitting it would destroy uniqueness in the Fundamental Theorem of Arithmetic.
- Claiming Euclid's proof produces a prime. need not be prime — — only that it has a prime factor outside the list.
- Trial dividing past . By Trial division stops at the square root the search may stop there; going further is wasted work, and stopping short of it is an error. Test itself when it is an integer.
- Assuming a negative remainder is allowed. The division algorithm demands , so , not . A language's
%operator may disagree. - Using Euclid's lemma with a composite modulus. but divides neither factor. The lemma is a statement about primes.
- Proving only existence and calling it the Fundamental Theorem. The existence half is a three-line induction; uniqueness is the content, and it needs Euclid's lemma.
- Extending to three or more numbers. It is false: .
- Reversing the Bézout coefficients. In the coefficient belongs to . Always substitute back and check the arithmetic; a sign slip here is the most common error in the extended algorithm.
- Reading Lamé's bound as a count rather than a ceiling. Five times the digit count is the worst case, achieved only by Fibonacci-like inputs; typical pairs finish in a fraction of that.