Arithmetic and NumbersDeeper

Kayavak / Arithmetic and Numbers / AN·05 Factors, Multiples and Primes / Deeper

Deeper · Arithmetic and Numbers

Factors, Multiples and Primes

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

Divisibility is older than written proofs: Babylonian scribes preferred base 60 partly because 60 has so many factors, and their reciprocal tables list only the "regular" numbers whose reciprocals end (those built from 2, 3 and 5). Euclid's Elements (about 300 BCE) collects the theory in Books VII to IX: the gcd algorithm opens Book VII, the fact that a prime dividing a product divides a factor is Book VII, Proposition 30, and the primes never running out is Book IX, Proposition 20. Eratosthenes' sieve comes from the following century.

The subject then went quiet for a long time. Pierre de Fermat revived it in the 1600s, stating (in a 1640 letter) the "little theorem" that ap−a is a multiple of p for every prime p, the basis of modern primality tests. Carl Friedrich Gauss's Disquisitiones Arithmeticae (1801) introduced the notation of congruences, a≡b(modm), and proved unique factorisation carefully. The prime number theorem, that primes near x have density about 1/lnx, was conjectured by Gauss and Legendre and proved in 1896, independently, by Jacques Hadamard and Charles de la Vallée Poussin. RSA (1977) made the whole subject practical; cryptographers at GCHQ, the British signals intelligence agency, had found an equivalent scheme in 1973, kept secret until 1997.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

Every whole number above 1 is a product of primes in exactly one way, and nearly every fact about divisibility is a fact about those prime exponents. Remainders behave like the numbers themselves, which turns divisibility questions into small calculations; and the gcd can be found by repeated remainders without factorising at all.

Question Answer
What is it? The theory of which whole numbers divide which, and of remainders
Problem it solves Simplifying, scheduling, checking and hiding numbers without doing the full calculation
Parts Divides, factors and multiples, remainders, primes, factorisation, gcd and lcm
How it works Place value gives the divisibility tests; remainders add and multiply; Euclid's algorithm shrinks pairs
Assumptions Whole numbers (negatives work with a remainder convention); divisors other than 0
When they change In some larger number systems factorisation isn't unique; with fractions every non-zero number divides every other
Where it fails gcd(0, 0) needs a convention; floating point breaks exact tests on large numbers
Related ideas Division with remainder (ch04), lowest terms (ch06), repeating decimals (ch07), number bases (ch02)

What if?

What if 1 counted as a prime?

Reason it through, then open

Nothing about numbers would change, but every statement about primes would need an exception. "Exactly one factorisation" would fail at once: 6 =2×3 =1×2×3 =1×1×2×3, so the theorem would have to say "apart from 1s". The sieve would cross out every number as a multiple of 1. Many writers before the 1900s did call 1 a prime; it was dropped because the exceptions piled up, not because of a discovery. The modern definition (exactly two factors) is a choice that makes the theorems clean.

What if there were only finitely many primes?

Reason it through, then open

Multiply them all and add 1. That number leaves remainder 1 on division by every prime on the list, so its prime factors (it has at least one, being above 1) aren't on the list: the list wasn't complete. This is Euclid's argument, and it shows what "finitely many" would break. Every number would be a product of a fixed handful of primes, so the counts of numbers up to x built from them would grow only like a power of lnx, far slower than x itself: there wouldn't be enough products to go round. Leonhard Euler turned that counting idea into a second proof in 1737, and it led eventually to the prime number theorem.

What if factoring large numbers became easy?

Reason it through, then open

RSA and every system built on it would break: anyone could recover a private key from the public one. That is exactly what Peter Shor's 1994 algorithm would do on a large enough quantum computer, which is why standards bodies are replacing RSA and elliptic-curve key exchange with "post-quantum" methods based on other hard problems. Gcds, primality tests and modular arithmetic would stay easy, as they are now; it's only the gap between multiplying and factoring that cryptography uses, and only that gap would close.

Where the boundary is

Aspect Testing whether a number is prime Finding its prime factors
Example Is 1,000,000,007 prime? What are the factors of a 600-digit product?
By trial division Up to n divisions Up to n divisions, the same
Best known method Fast (Miller–Rabin in practice; AKS proved polynomial time in 2002) No known polynomial-time method on ordinary computers
Answer for a 600-digit number Seconds Far beyond any computer today
Used for Generating cryptographic keys Breaking them; so its difficulty is the security

Derive it

Why a prime dividing a product must divide one of the factors, from Euclid's algorithm.

  1. Run Euclid's algorithm backwards. For 1071 and 462: 1071=2×462+147, 462=3×147+21, 147=7×21.
  2. Rewrite the last useful line as 21=462−3×147, then replace 147 using the first line: 21 =462−3×(1071−2×462) =7×462−3×1071.
  3. The same steps work for any pair, so the gcd of a and b can always be written as as+bt for some whole numbers s and t (one of them negative). This is Bézout's identity.
  4. Now let a prime p divide a×b but not a. The only factors of p are 1 and p, so gcd(p,a)=1, and step 3 gives 1=ps+at.
  5. Multiply by b: b=pbs+abt. The prime p divides pbs and it divides ab, so it divides the right-hand side, which is b.
  6. Uniqueness of factorisation follows: if two factorisations differed, a prime from one would divide the product of the other, so by step 5 it would divide (and so equal) one of its primes; cancel it and repeat.

How sure are we?

Claim How it's known Where from
There are infinitely many primes Theorem Euclid, Elements IX.20; the chapter's proof
Every number above 1 factors into primes in exactly one way Theorem Gauss (1801); the derivation above
Euclid's algorithm takes at most about five times the digits of the smaller number Theorem Lamé (1844); the chapter's lab found at most 23 steps over 100,000 pairs below a million
Primes near x have density about 1/lnx Theorem Prime number theorem, proved 1896; the lab's counts match it
Primality can be tested in polynomial time Theorem Agrawal, Kayal and Saxena (2002)
Factoring large numbers is hard for ordinary computers Active research No proof exists; it isn't even known to be truly harder than primality
Every even number above 2 is a sum of two primes Active research Goldbach's conjecture (1742); checked by computer to 4×1018
1 is not a prime Convention The modern definition; it keeps the theorems free of exceptions

Still open

Much of the subject is open, and simply stated. The Riemann hypothesis (1859), about exactly how regularly the primes are spread, is the most famous unsolved problem in mathematics. Nobody knows whether there are infinitely many twin primes, whether Goldbach's conjecture holds, or whether there are infinitely many Mersenne primes (2k−1), the form of the largest primes known: the record in 2024 had over 41 million digits. And whether factoring is genuinely hard, the assumption beneath public-key cryptography, is not proved.

What would change your mind? The chapter says testing primality is easy and factoring is hard. An algorithm that factored 600-digit numbers quickly on ordinary computers would overturn the second half, and with it much of internet security; a proof that no such algorithm exists would turn a belief into a theorem.

Recall

Why is 1 not counted as a prime?

With it, factorisations wouldn't be unique (any number of 1s could be added); the definition "exactly two factors" excludes it.

What does Euclid's algorithm repeat?

Replace the pair (a, b) by (b, remainder of a divided by b) until the remainder is 0; the last non-zero remainder is the gcd.

What is Bézout's identity?

The gcd of a and b can be written as a·s + b·t for whole numbers s and t, found by running Euclid's algorithm backwards.

When does a prime dividing a product divide one of the factors?

Always, for primes (Euclid's lemma); for composites it can fail, as 6 divides 4 × 9 but neither factor.

What gap does RSA rely on?

Multiplying primes and testing primality are fast, but factoring a large product is not known to be.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.