Prime Factorization

Chapter 7: Number Theory

Learning objectives

  • State the Fundamental Theorem of Arithmetic
  • Use Euclid’s lemma to prove uniqueness of factorisation
  • Apply the Sieve of Eratosthenes to enumerate primes
  • Reproduce Euclid’s proof of the infinitude of primes

If integers are the atoms of arithmetic, primes are the protons. Every positive integer above 11 breaks down into primes in exactly one way, and that uniqueness is the single most important fact in all of elementary number theory. It is what makes modular arithmetic well-behaved, what makes RSA encryption a one-way street (multiplying two huge primes is fast; factoring their product takes geological time on classical hardware), and what makes “find a hash collision” a meaningful challenge in cryptocurrency proof-of-work. Cantor used uniqueness of factorisation to encode finite sets as integers; Gödel used it to encode logical proofs as integers. The Fundamental Theorem of Arithmetic earns its name.

Primes and composites

An integer p>1p > 1 is prime if its only positive divisors are 11 and pp. Otherwise (and n>1n > 1) it is composite. The integer 11 is neither — treating it as prime would break uniqueness of factorisation (you could insert any number of 11 factors).

The Fundamental Theorem of Arithmetic

Every integer n>1n > 1 can be written as n=p1a1p2a2pkakn = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k} where the pip_i are distinct primes and the ai1a_i \geq 1, and this representation is unique up to the order of the factors. Existence follows from strong induction: either nn is prime (done) or n=abn = ab for some 1<a,b<n1 < a, b < n, both of which factor by the induction hypothesis.

Uniqueness requires a deeper tool, Euclid’s lemma: if a prime pp divides abab, then pap \mid a or pbp \mid b. Proof: if pap \nmid a, then gcd(p,a)=1\gcd(p, a) = 1 (the only divisors of pp are 11 and pp). By Bezout, sp+ta=1sp + ta = 1; multiplying by bb gives spb+tab=bspb + tab = b, and since pabp \mid ab, pp divides both terms on the left, hence pbp \mid b. Iterating Euclid’s lemma forces any two factorisations of nn to match prime-by-prime.

The Sieve of Eratosthenes

To list every prime N\leq N: write 2,3,,N2, 3, \ldots, N. Cross out the multiples of 22 (except 22 itself); move to the next surviving number (33) and cross out its multiples; continue with 5,7,5, 7, \ldots up to N\lfloor \sqrt{N} \rfloor. Whatever survives is prime. Reason for stopping at N\sqrt{N}: a composite nNn \leq N must have a divisor nN\leq \sqrt{n} \leq \sqrt{N}, so it would have already been crossed out.

Euclid’s proof of infinitely many primes

Suppose for contradiction the complete list of primes is p1,p2,,pkp_1, p_2, \ldots, p_k. Consider N=p1p2pk+1N = p_1 p_2 \cdots p_k + 1. Then N>1N > 1, so it has a prime factor pp. But pp cannot be any pip_i, because dividing NN by pip_i leaves remainder 11. So pp is a prime missing from our supposedly complete list — contradiction. (Note: NN itself is not necessarily prime; the argument only needs that some prime factor of NN lies outside the list.)

Pause and think: Why does the FTA fail if we allow 11 as a prime? Try writing the factorisation of 1212 in two ways using 11 as a permitted factor — you will see immediately why 11 has to be excluded.

Try it

  • Predict first: how many primes lie between 11 and 3030? Then run the Sieve mentally (cross out multiples of 2,3,52, 3, 5; 30=5\lfloor \sqrt{30} \rfloor = 5, so stop there) and count.
  • Factorise 25202520 into primes. (It is famous for having lots of small factors.) Use your factorisation to compute the number of positive divisors of 25202520.
  • Verify Euclid’s construction with {2,3}{2, 3} as the “complete” list: N=23+1=7N = 2 \cdot 3 + 1 = 7. Is 77 prime? Repeat with {2,3,5,7,11,13}{2, 3, 5, 7, 11, 13}: is N=30031N = 30031 prime? (It is not — see if you can factor it.)
  • Two-step puzzle: explain why n21n^2 - 1 is never prime when n3n \geq 3. (Factor n21n^2 - 1 as a product first.)

A trap to watch for

It is tempting to test whether nn is prime by checking divisibility for every integer up to n1n - 1 — but you only need to test up to n\lfloor \sqrt{n} \rfloor. Reason: if n=abn = a \cdot b with aba \leq b, then ana \leq \sqrt{n}. So either you find a factor n\leq \sqrt{n}, or there is none and nn is prime. A related trap: Euclid’s proof shows there are infinitely many primes, but it does not show that p1p2pk+1p_1 p_2 \cdots p_k + 1 is itself prime — only that some prime factor of it is new. Students sometimes mis-remember this as “the Euclid construction always produces a new prime,” which is false (try {2,3,5,7,11,13}{2, 3, 5, 7, 11, 13} above).

Code ChallengeInteractive figure — enable JavaScript to interact.

What you now know

You can decompose any integer into primes, justify the uniqueness of that decomposition via Euclid’s lemma, sieve out primes up to a given bound, and produce Euclid’s elegant contradiction proof that primes go on forever. Next section, modular arithmetic, recasts “same prime factorisation up to” ideas as algebra on equivalence classes.

References

  • Velleman, D. J. (2019). How to Prove It: A Structured Approach (3rd ed.). Cambridge University Press, §7.2.
  • Hardy, G. H., Wright, E. M. (2008). An Introduction to the Theory of Numbers (6th ed.). Oxford University Press, ch. 1–2.
  • Niven, I., Zuckerman, H. S., Montgomery, H. L. (1991). An Introduction to the Theory of Numbers (5th ed.). Wiley, ch. 1–2.
  • Rosen, K. H. (2010). Elementary Number Theory (6th ed.). Pearson, ch. 3.
  • Koblitz, N. (1994). A Course in Number Theory and Cryptography (2nd ed.). Springer, ch. 1.

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.