Primes and Composites
Progress can't be saved in this browser, so this lesson's status can't be set.
Watch the video explainer
Learning goals
- Define prime and composite by counting a number's factors
- Explain why is neither prime nor composite and why is the only even prime
- Test a number by trial division, stopping once the divisor times itself passes it
- Run the Sieve of Eratosthenes to list primes up to a limit
Factors, the starting point
A factor (or divisor) here means a positive whole number that divides a number without a remainder. For , the factors are
Every whole number greater than has and itself as two distinct factors. The question is whether it has any others.
Defining prime and composite
Count distinct factors only: a factor counts once, even when it appears twice in a factor pair.
A whole number greater than is prime when it has exactly two distinct factors: and itself, and nothing in between. The number is prime because the only whole numbers that divide it are and . Try anything else, say , , , , or , and a remainder appears.
A whole number greater than is composite when it has more than two distinct factors. The number is composite because, beyond and , the numbers and also divide it. Having even one extra factor is enough to make a number composite.
Use the rows below to check those definitions. Change the number of dots and the row width. A full set of rows means the width is a factor; hollow dots in a short row mean it is not.
Which row widths a number allows
12 dots in rows of 4 make 3 full rows with none left over. So 12 = 3 times 4. So 4 is a factor of 12.
Try dots with row widths through . The widths , , , and fit, so is composite. Now try dots with the same widths. Every width leaves a remainder; only and fit, so is prime.
Every whole number greater than is exactly one of prime or composite. Its factors either stop at and itself, or include at least one more.
Zero is outside both definitions: it is not greater than .
Why 1 is neither prime nor composite
The number has just one factor, . The phrases "" and “itself” name the same factor, so they do not count twice. A prime needs two distinct factors, and a composite needs more than two; is neither.
There is a useful reason for keeping out of the prime list. Multiplying by never changes a number:
If counted as prime, a list of prime factors could gain extra s without changing its product. The next lesson uses a prime list that is unique apart from order.
Why 2 is the only even prime
The factors of are just and , so is prime. For a larger even number, such as , being even supplies an extra factor, . Its factors include , , and , already too many for a prime.
The same reasoning applies to every even number greater than : the factor is different from both and the number itself. Thus is the only even prime. Being odd does not guarantee being prime: is odd and composite.
Check your understanding
How many of these four numbers are prime: , , , ?
Check each against the definition (exactly two distinct factors, and greater than ).
The number has one distinct factor, so it is neither prime nor composite. The number is composite:
That leaves (factors ) and (factors ) as the primes, so the count is .
Check your understanding
Which explanation correctly describes both and even numbers greater than ?
The number has only the factor , so it meets neither definition. The number has exactly the factors and , so it is prime.
Every larger even number has at least three distinct factors: , , and itself. For example, has , so it is composite.
Testing a number by trial division
Trial division means testing possible divisors in turn. For a number greater than , a factor other than and itself proves it composite. The divisibility rules make the first tests easy:
- Test : an even number greater than is composite.
- Test : use the digit sum, setting itself aside as prime.
- Test : look for a last digit of or , setting itself aside as prime.
- Test larger primes: try , , , and so on, until a factor appears or the stopping rule applies.
Why skip composite divisors? If divided your number, would divide it too; if divided it, would. More generally, a composite divisor has a smaller prime factor. That smaller prime would already have been tested. The next section tells you how far the search needs to go.
The stopping rule: when can you quit?
Factors come in pairs, so a search can stop before reaching the number itself. For , the pairs are , , , , and . Each pair has a smaller partner at most , and . A factor above would be the larger partner of a pair found earlier.
For a whole number greater than , test prime divisors while . Stop once . A factor found makes composite; if every prime in that range fails, is prime. The equal case counts too: still needs the test at , since .
Every composite has a small partner to find: two factors both past the stopping point would multiply to more than the number. Checking the smaller partners therefore covers every possible pair.
Worked example 1 Is prime or composite?
The number is odd and does not end in or , so and are out. Try the next candidate, , with the digit-sum rule:
so divides . That is a third factor besides and :
So is composite. The digit-sum test for catches factors the eye misses, so run it early.
Worked example 2 Is prime or composite?
Test divisors in order, stopping once a divisor times itself passes .
It is odd, so fails. Its digit sum is , not a multiple of , so fails. It does not end in or , so fails. Try :
so fails too. The next candidate is , but check the stopping rule first:
so we have passed the stopping point. No divisor up to here worked, so there is no factor pair to find. Therefore is prime. Notice we only had to try and .
Check your understanding
You are testing whether is prime by trying prime divisors. What is the largest prime you need to test before you can stop?
Keep testing divisors while , and stop once passes .
So the prime candidates you test are , and the largest of these is . The next prime, , already has , so you stop before testing it.
Worked example 3 List every prime between and
Run each candidate through the quick tests, remembering that any even number or any multiple of in this range is composite immediately.
The even numbers and the multiple of , namely , are all composite. That leaves the odd, non-multiple-of- numbers to examine:
so and are composite (both have digit sums divisible by ). Now test and . Neither is even, neither is a multiple of ( and ), and neither ends in or . The next divisor would be , but already passes both numbers, so we stop.
Therefore the primes between and are
Check your understanding
Which one of these numbers is prime?
Clear three of them with the rules you already know, then confirm the fourth with the stopping rule.
The first two are caught by the digit-sum rule for and the ends-in--or- rule for . The number passes both of those but fails at , so it is composite too. For : it is odd, its digit sum is not a multiple of , and it does not end in or . The next candidate is , but , so the search stops there. None of the tested primes divides , so it is prime.
The Sieve of Eratosthenes
To find all the primes up to a limit, cross out composites together instead of testing each number separately. This is the Sieve of Eratosthenes: like a sieve separating objects, it removes the numbers you do not want and leaves the primes.
Write the whole numbers from to the limit. Circle and cross out its larger multiples. Then circle the smallest number neither circled nor crossed out, and cross out its larger multiples. Repeat with the next such number.
Why is each newly circled number prime? Any smaller factor would already have caused it to be crossed out. Keep the circled prime itself; only its larger multiples are composite.
For a limit of , the passes for , , and remove every composite. The next prime is , and . By the stopping rule, every uncrossed number is now prime.
Check your understanding
Run the Sieve of Eratosthenes from through . Which list remains after the composites are crossed out?
Keep and cross out its larger multiples: . Keep and cross out its larger multiples; this removes the remaining and .
The next surviving prime is , and , so no further pass is needed. The survivors are . Keep even though it is even; do not add , and do not keep the composite .