Skip to content
Number Theory · Chapter 17

Primes and Divisibility

Spot primes, test divisibility in your head, break numbers into primes, and count the zeros at the end of a factorial.

You'll need
open on YouTube
17.10%

Primes

In this section you will be able to spot prime numbers and test whether a number is prime using only primes up to its square root.

Try to split 12 cookies into equal rows. You can make rows of 2, 3, 4 or 6. Now try 13 cookies. Only one long row works! Numbers like 13 are called primes.

A prime can’t be split into a product of smaller numbers. Every other number bigger than 1 can.

The sieve finds primes by crossing out multiples. Look: once you have swept every prime up to the square root of the biggest number, nothing new gets crossed out.

Exploreplay first, formulas later

Numbers 1 to 120, nothing swept yet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Press "Sweep 2" to cross out the multiples of 2.

Press "Sweep 2" to cross out the multiples of 2.

Name it

Definition 17.1.1 · Primes

Primes are numbers that have exactly two factors: 11 and the number itself.

Example: 2,3,5,7,11,13,17,19,232, 3, 5, 7, 11, 13, 17, 19, 23 are all primes.

Note: 11 is not a prime (it has only one factor), and 22 is the only even prime.

Remark 17.1.2

It's highly recommended to memorize the first few primes, as this can save some time during the contest:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 372,\ 3,\ 5,\ 7,\ 11,\ 13,\ 17,\ 19,\ 23,\ 29,\ 31,\ 37

Remark 17.1.3

To check whether a number nn is prime, you only need to check whether it can be divided by the primes that are less than or equal to n\sqrt{n}.

For example, 91≈9.5\sqrt{91} \approx 9.5, so you test 2,3,5,72, 3, 5, 7. And 91=7×1391 = 7 \times 13, so 9191 is not prime.

Try it

Problem 17.5.1

AMC 8

Which of the following numbers has the smallest prime factor?

(A) 55 (B) 57 (C) 58 (D) 59 (E) 61

Problem 17.5.4

AMC 8

The sum of two prime numbers is 85. What is the product of these two prime numbers?

Contest cornerreal contest problems

Problem 17.5.7

AMC 8

What is the smallest positive integer that is neither prime nor square and that has no prime factor less than 50?

Problem 17.5.10

AMC 8

Three members of the Euclid Middle School girls' softball team had the following conversation.

Ashley: I just realized that our uniform numbers are all 2-digit primes.

Brittany: And the sum of your two uniform numbers is the date of my birthday earlier this month.

Caitlin: That's funny. The sum of your two uniform numbers is the date of my birthday later this month.

Ashley: And the sum of your two uniform numbers is today's date.

What number does Caitlin wear?

Checkpoint for section 17.1

Get 2 of 3 right to master this section. One try each, no hints.
1

Is 1 a prime number?

2

To check whether 143 is prime, what is the largest prime you need to test?

3

How many primes are there between 20 and 40?

17.20%

Divisibility Rules

In this section you will be able to decide whether a number is divisible by 2 through 12 or 15 without doing the long division.

Is 4,827,676 divisible by 8? You could do a long division. Or you could look at just three digits and know in a few seconds.

Each rule only looks at part of the number: the last digit, the last few digits, or the digit sum. The rest of the number is a multiple of 10, 100 or 1000 and never changes the answer.

For 6, 12 and 15, check two simpler rules. A number divisible by 3 and by 4 is divisible by 12.

Exploreplay first, formulas later

172947 is not divisible by 4: Last 2 digits: 47 = 4 × 11 + 3, not a multiple of 4.

Tap a digit to add 1 to it.

  • Last 2 digits: 47 = 4 × 11 + 3, not a multiple of 4.
172947 is not divisible by 4

Check by dividing: 172947 ÷ 4 = 43236 remainder 3

172947 is not divisible by 4. Last 2 digits: 47 = 4 × 11 + 3, not a multiple of 4.

Name it

Concept 17.2.1 · Divisibility Rules

Divisor Rule
2 Last digit is even
3 Sum of digits is divisible by 3
4 Last 2 digits divisible by 4
5 Last digit is 0 or 5
6 Divisible by 2 and 3
7 Take out multiples of 7 until you reach a small number that is either divisible or not divisible by 7
8 Last 3 digits are divisible by 8
9 Sum of digits is divisible by 9
10 Last digit is 0
11 Add the digits in odd positions (OO) and in even positions (EE). If ∣O−E∣\lvert O - E \rvert is divisible by 11, so is the number
12 Divisible by 3 and 4
15 Divisible by 3 and 5

Remark 17.2.2

In general, if a number is divisible by 2 different primes or prime powers (numbers that are powers of a prime, like 353^5 or 242^4), then it is also divisible by their product.

For example, to find whether a number is divisible by 30=2×3×530 = 2 \times 3 \times 5, you just check whether it's divisible by each of 22, 33 and 55 using the divisibility rules.

Try it

Problem 17.5.3

AMC 8

How many three-digit numbers are divisible by 13?

Problem 17.5.17(additional)

AMC 8

The number 64 has the property that it is divisible by its units digit. How many whole numbers between 10 and 50 have this property?

Problem 17.5.6

AMC 8

The 5-digit number 2‾ 0‾ 1‾ 8‾ U‾\underline{2}\,\underline{0}\,\underline{1}\,\underline{8}\,\underline{U} is divisible by 9. What is the remainder when this number is divided by 8?

Contest cornerreal contest problems

Problem 17.5.5

The 7-digit numbers 74A52B1 and 326AB4C are each multiples of 3. Which of the following could be the value of C?

(A) 1 (B) 2 (C) 3 (D) 5 (E) 8

Problem 17.5.12

AMC 8

The digits 1, 2, 3, 4, and 5 are each used once to write a five-digit number PQRST. The three-digit number PQR is divisible by 4, the three-digit number QRS is divisible by 5, and the three-digit number RST is divisible by 3. What is P?

Problem 17.5.14

AMC 10

Call a positive integer an uphill integer if every digit is strictly greater than the previous digit. For example, 1357, 89, and 5 are all uphill integers, but 32, 1240, and 466 are not. How many uphill integers are divisible by 15?

Problem 17.5.19(additional)

MATHCOUNTS

Ayasha, Beshkno, and Chenoa were all born after 2000. Each of them was born in a year after 2000 that is divisible by exactly one of the prime numbers 2, 3 or 5. Each of these primes is a divisor of one of the birth years. What is the least possible sum of their birth years?

Checkpoint for section 17.2

Get 2 of 3 right to master this section. One try each, no hints.
1

The number 64 has the property that it is divisible by its units digit. How many whole numbers between 10 and 50 have this property?

2

Is 5,214 divisible by 9?

3

What digit dd makes the number 7d437d43 divisible by 11?

17.30%

Prime Factorization

In this section you will be able to write any number as a product of primes, and use that to break hard divisibility problems into easy rules.

Every number is built from primes, like a house from bricks. 60 is 2 × 2 × 3 × 5, and no other set of primes makes 60.

A prime factorization writes a number as a product of primes, like 60=22×3×560 = 2^2 \times 3 \times 5. However you split, you end with the same primes.

To test divisibility by a big number like 264, factor it first: 264=8×3×11264 = 8 \times 3 \times 11. Then use the rules for 8, 3 and 11.

Exploreplay first, formulas later

Prime factorization of 60: 2^2 × 3 × 5

Split 60 as:

60 = 60keep splitting

60 = 60. Some leaves can still be split.

Name it

Remark 17.3.1

In these types of problems, it's almost always best to first find the prime factorization of the number, and then use the divisibility rules for each of the primes or prime powers in the prime factorization.

Watch itpredict, then reveal

Example 17.1

Find the prime factorization of 117.

Prime factorization of 117: 3^2 × 13

Split 117 as:

117 = 117keep splitting

117 = 117. Some leaves can still be split.

  1. 1

    Is 117 divisible by 2?

    Predict first:

Example 17.2

AMC 8

Let ZZ be a 6-digit positive integer, such as 247247, whose first three digits are the same as its last three digits taken in the same order. Which of the following numbers must also be a factor of ZZ?

(A) 11 (B) 19 (C) 101 (D) 111 (E) 1111

Prime factorization of 1,001: 7 × 11 × 13

Split 1,001 as:

1,001 = 1001keep splitting

1001 = 1001. Some leaves can still be split.

  1. 1

    Split 247247247247 into 247×1000+247247 \times 1000 + 247. What is 247247÷247247247 \div 247?

    Predict first:
open on YouTube

Example 17.3

MATHCOUNTS

What four-digit number has tens digit 2 and units digit 8, is a multiple of 16, and when its digits are reversed the result is also a multiple of 16?

128 is divisible by 8: Last 3 digits: 128 = 8 × 16.

Tap a digit to add 1 to it.

  • Last 3 digits: 128 = 8 × 16.
128 is divisible by 8

Check by dividing: 128 ÷ 8 = 16

128 is divisible by 8. Last 3 digits: 128 = 8 × 16.

  1. 1

    Call the number ab28ab28. Every multiple of 16 is a multiple of 8. What does the rule for 8 say about the last three digits b28b28?

    Predict first:
open on YouTube

Example 17.4

AMC 8

A number is called flippy if its digits alternate between two distinct digits. For example, 2020 and 37373 are flippy, but 3883 and 123123 are not. How many five-digit flippy numbers are divisible by 15?

50505 is divisible by 15: Check 3: Digit sum 5 + 0 + 5 + 0 + 5 = 15, a multiple of 3. Check 5: Last digit 5 is 0 or 5. Divisible by both 3 and 5.

Tap a digit to add 1 to it.

  • Check 3: Digit sum 5 + 0 + 5 + 0 + 5 = 15, a multiple of 3.
  • Check 5: Last digit 5 is 0 or 5.
  • Divisible by both 3 and 5.
50505 is divisible by 15

Check by dividing: 50505 ÷ 15 = 3367

50505 is divisible by 15. Check 3: Digit sum 5 + 0 + 5 + 0 + 5 = 15, a multiple of 3. Check 5: Last digit 5 is 0 or 5. Divisible by both 3 and 5.

  1. 1

    Divisible by 15 means divisible by which two numbers?

    Predict first:
open on YouTube

Example 17.5

Omega Learn

The 3 digit number A3B is divisible by 15. What is the sum of all such possible numbers?

130 is not divisible by 15: Check 3: Digit sum 1 + 3 + 0 = 4, not a multiple of 3. Check 5: Last digit 0 is 0 or 5. Fails the 3 test, so not divisible by 15.

Tap a digit to add 1 to it.

  • Check 3: Digit sum 1 + 3 + 0 = 4, not a multiple of 3.
  • Check 5: Last digit 0 is 0 or 5.
  • Fails the 3 test, so not divisible by 15.
130 is not divisible by 15

Check by dividing: 130 ÷ 15 = 8 remainder 10

130 is not divisible by 15. Check 3: Digit sum 1 + 3 + 0 = 4, not a multiple of 3. Check 5: Last digit 0 is 0 or 5. Fails the 3 test, so not divisible by 15.

  1. 1

    For a number to be divisible by 15, what other numbers must it be divisible by?

    Predict first:

Example 17.6

Omega Learn

The number 3AB76 is divisible by 264, where A and B are digits. Find A + B.

Prime factorization of 264: 2^3 × 3 × 11

Split 264 as:

264 = 264keep splitting

264 = 264. Some leaves can still be split.

  1. 1

    For a number to be divisible by 264, what other numbers must it be divisible by?

    Predict first:

Try it

Problem 17.5.2

AMC 8

What is the sum of the two smallest prime factors of 250?

Problem 17.5.15(additional)

What is the prime factorization of 420?

Problem 17.5.16(additional)

What is the prime factorization of 1001?

Problem 17.5.8

AMC 8

If 3p+34=903^p + 3^4 = 90, 2r+44=762^r + 44 = 76, and 53+6s=14215^3 + 6^s = 1421, what is the product of pp, rr, and ss?

Contest cornerreal contest problems

Problem 17.5.11

Omega Learn Math Contest

The number AB962C is divisible by 792 where A, B, C are digits. What is the value of A?

Problem 17.5.18(additional)

Omega Learn

The number 8173ABC is divisible by 165. What is the average of all such 3 digit numbers ABC that satisfy this condition?

Problem 17.5.20(additional)

Omega Learn

Sohil is thinking of a 5 digit number such that the first 3 digits are divisible by 63, the middle 3 digits are divisible by 8, and the last 3 digits are divisible by 11. What is the largest possible number he can be thinking of?

Checkpoint for section 17.3

Get 2 of 3 right to master this section. One try each, no hints.
1

What is the prime factorization of 420?

2

What is the prime factorization of 1001?

3

What is the largest prime factor of 1001?

17.40%

Legendre’s Formula

In this section you will be able to count how many times a prime divides n!, and how many zeros n! ends with.

10! = 3,628,800 ends in two zeros. How many zeros does 100! end with? It has 158 digits, so you’ll want a shortcut!

Each multiple of pp gives one factor of pp. Multiples of p2p^2 hide a second one, multiples of p3p^3 a third. Count them layer by layer.

Exploreplay first, formulas later

Factors of 2 in 10!: 5 + 2 + 1 = 8

n10
246810
  • Layer 1: multiples of 2 = 2 up to 10: 5
  • Layer 2: multiples of 2² = 4 up to 10: ?
  • Layer 3: multiples of 2³ = 8 up to 10: ?
2s in 10!: 5 = 5 so far

2 in 10!: 5 = 5 so far

Name it

Theorem 17.4.1 · Legendre's Theorem

The number of factors of a prime pp in n!n! is

vp(n!)=⌊np⌋+⌊np2⌋+⌊np3⌋+⋯v_p(n!) = \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 xx down to a whole number".

Watch itpredict, then reveal

Example 17.7

Find the number of 0's at the end of 100!.

Factors of 5 in 100!: 20 + 4 = 24

5101520253035404550556065707580859095100
  • Layer 1: multiples of 5 = 5 up to 100: ?
  • Layer 2: multiples of 5² = 25 up to 100: ?
5s in 100!: 0 so far

5 in 100!: 0 so far

  1. 1

    Each 0 at the end comes from a factor of 10=2×510 = 2 \times 5. Which factor is rarer in 100!100!, 2 or 5?

    Predict first:
open on YouTube

Contest cornerreal contest problems

Problem 17.5.9

AMC 8

For any positive integer MM, the notation M!M! denotes the product of the integers 1 through MM. What is the largest integer nn for which 5n5^n is a factor of the sum 98!+99!+100!98! + 99! + 100! ?

Problem 17.5.13

AMC 10

The base-ten representation for 19!19! is 121,6T5,100,40M,832,H00121{,}6T5{,}100{,}40M{,}832{,}H00, where TT, MM, and HH denote digits that are not given. What is T+M+HT + M + H?

Checkpoint for section 17.4

Get 2 of 3 right to master this section. One try each, no hints.
1

How many factors of 2 are in 10!10!?

2

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

3

How many factors of 3 are in 30!30!?

17.5

Practice Problems

In this section you will be able to mix primes, divisibility rules and factorizations on contest problems.

One last puzzle that uses the rules for 2, 3, 4, 5 and 6 all at once. Every problem has three hints if you get stuck.

Want every problem from this chapter on one page? Open the problem set.

Contest cornerreal contest problems

Problem 17.5.21(additional)

BmMT

How many permutations of 123456 are divisible by their last digit? For instance, 123456 is divisible by 6, but 561234 is not divisible by 4.