Math Core

Module 3.2 · Number Theory

Primes and prime factorization

Every whole number greater than 11 is built from primes in exactly one way, the way a molecule is built from atoms. Once you write a number as a product of primes, many contest questions become bookkeeping: perfect squares, factors of factorials, and "what must divide this?"

Primes and how to test them

Definition

Prime number

A prime is a whole number greater than 11 whose only positive divisors are 11 and itself. A whole number greater than 11 that is not prime is composite. The number 11 is neither.

The primes below 5050 are worth memorizing: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,472, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47.

Notice that 22 is the only even prime. This one fact solves a surprising number of problems: if two primes add to an odd number, one of them must be 22.

Testing a number for primality. If nn is composite, it can be written as a×ba \times b with a≤ba \le b. Then a×a≤na \times a \le n, so a≤na \le \sqrt{n}. That means you only need to check primes up to n\sqrt{n}.

Worked example: Is 221 prime?

221\sqrt{221} is a bit less than 1515 (since 152=22515^2 = 225), so test the primes 2,3,5,7,11,132, 3, 5, 7, 11, 13.

221221 is odd, its digit sum is 55, and it doesn't end in 00 or 55. Try 77: 7×31=2177 \times 31 = 217, remainder 44. Try 1111: alternating sum 2−2+1=12 - 2 + 1 = 1, no. Try 1313: 13×17=22113 \times 17 = 221. So 221221 is composite.

Common mistake

Numbers like 91=7⋅1391 = 7 \cdot 13, 119=7⋅17119 = 7 \cdot 17, 133=7⋅19133 = 7 \cdot 19, 143=11⋅13143 = 11 \cdot 13 and 221=13⋅17221 = 13 \cdot 17 "look prime" and trap students every year. Always finish the check up to n\sqrt{n}.

Prime factorization

Fundamental Theorem of Arithmetic

Every whole number greater than 11 can be written as a product of primes in exactly one way (ignoring order). For example, 540=22⋅33⋅5540 = 2^2 \cdot 3^3 \cdot 5.

To find it, divide out small primes one at a time: 540→270→135→45→15→5→1540 \to 270 \to 135 \to 45 \to 15 \to 5 \to 1, dividing by 2,2,3,3,3,52, 2, 3, 3, 3, 5.

Perfect powers. A number is a perfect square exactly when every exponent in its factorization is even, and a perfect cube when every exponent is a multiple of 33.

Worked example: Make a perfect square

What is the smallest positive integer nn such that 540n540n is a perfect square?

540=22⋅33⋅5540 = 2^2 \cdot 3^3 \cdot 5. The exponent of 33 is odd and the exponent of 55 is odd. Multiply by one more 33 and one more 55: n=15n = 15. Then 540⋅15=8100=902540 \cdot 15 = 8100 = 90^2.

Worked example: What must divide it?

A six-digit number has the form A‾ B‾ A‾ B‾ A‾ B‾\underline{A}\,\underline{B}\,\underline{A}\,\underline{B}\,\underline{A}\,\underline{B}, like 272727272727. Which prime greater than 3030 must divide every such number?

A‾ B‾ A‾ B‾ A‾ B‾=A‾ B‾×10101\underline{A}\,\underline{B}\,\underline{A}\,\underline{B}\,\underline{A}\,\underline{B} = \underline{A}\,\underline{B} \times 10101, and 10101=3⋅7⋅13⋅3710101 = 3 \cdot 7 \cdot 13 \cdot 37. So every such number is divisible by 3,7,133, 7, 13 and 3737. The prime greater than 3030 is 37.

Primes inside factorials

How many times does the prime pp divide n!n!? Count the multiples of pp up to nn, then add the multiples of p2p^2 (each contributes an extra factor), then p3p^3, and so on:

⌊np⌋+⌊np2⌋+⌊np3⌋+⋯\left\lfloor \frac{n}{p} \right\rfloor + \left\lfloor \frac{n}{p^2} \right\rfloor + \left\lfloor \frac{n}{p^3} \right\rfloor + \cdots

Here ⌊x⌋\lfloor x \rfloor means "round down to a whole number."

Worked example: Trailing zeros

How many zeros are at the end of 100!100!?

Each trailing zero is a factor of 10=2⋅510 = 2 \cdot 5. There are far more 22s than 55s, so count the 55s: ⌊1005⌋+⌊10025⌋=20+4=24\left\lfloor \dfrac{100}{5} \right\rfloor + \left\lfloor \dfrac{100}{25} \right\rfloor = 20 + 4 = 24.

So 100!100! ends in 24 zeros. The numbers 25,50,75,10025, 50, 75, 100 each contribute two 55s, which the second term counts.

Practice

Practice 1

What is the sum of all prime numbers between 3030 and 5050?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

What is the sum of the distinct prime factors of 30033003?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Which of the following is prime?

Practice 4

Two prime numbers differ by 1717. What is their sum?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

What is the smallest positive integer nn such that 180n180n is a perfect square?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

What is the smallest positive integer nn such that 360n360n is a perfect cube?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

How many zeros are at the end of 60!60!?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

What is the largest integer kk such that 12k12^k divides 30!30!?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Real contest practice