Primes and Composites
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 quick reminder from the last lesson. A factor (or divisor) of a whole number is a whole number greater than that divides leaving remainder . To list the factors of , you ask of each candidate “does it divide evenly?” The factors of are
because each of these divides with nothing left over, and no other whole number does. Two of those factors come free for every whole number greater than . Every such number is always divisible by (one group containing everything) and by itself (one group the size of the whole number). So the real question, the one that sorts numbers into two camps, comes down to this. Does a number have only those two forced factors, or does it have more?
Defining prime and composite
This is the whole idea, stated carefully. We count only the distinct factors, and we work with whole numbers greater than .
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.
Both of those claims are things you can check rather than take on trust. Below you choose how many dots there are and how many go in each row. When every row comes out full, the row width is a factor. When the last row is short, it is not, and the leftover dots are drawn hollow so you can count them.
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.
Set the count to and walk the row width from up to . Widths , , and all come out full, and only leaves anything over, so has factors to spare and is composite. Now set the count to and walk the same widths again. Every single one leaves a short row. Nothing between and divides it, which is exactly what makes prime, and you have now checked it rather than been told it.
Every whole number greater than falls into exactly one of these two groups, never both and never neither. Either its only factors are and itself (prime), or it has at least one more (composite). Here is the start of the list, sorted:
Why 1 is neither prime nor composite
The number looks like it might be prime, since nothing divides it except . But run it through the definition exactly. A prime needs two distinct factors. The number has only one factor, namely itself: the "" and the “itself” are the same number, so they do not count twice.
The exclusion of is not just a bookkeeping rule. It keeps every whole number’s breakdown into primes unique: if counted as prime, you could glue extra copies of it onto any breakdown () and never land on one settled answer. The next lesson, on prime factorization, depends on that uniqueness, which is why is kept out.
Why 2 is the only even prime
Look at the prime list again: . After , every entry is odd. That is no accident.
Try to find an even number past that survives the definition. Take . Being even hands it as a factor for free, on top of the and the that every number is forced to have. Its factor list is , which is four factors, and a prime is allowed exactly two.
The same thing happens for any even number bigger than , not just : being even hands it as an extra factor, on top of the and itself it already has. That is three distinct factors, one more than a prime is allowed, so the number is composite. Every even number past fails the same way, which leaves as the only even prime.
This gives you a fast first filter. If a number bigger than ends in or , you can declare it composite on sight, no division needed. The candidates for “prime” past are only the odd numbers, and even among those, plenty (like , , ) turn out to be composite.
Check your understanding
How many of these four numbers are prime: , , , ?
Check each against the definition (exactly two distinct factors, and greater than ).
That leaves (factors ) and (factors ) as the primes, so the count is .
Testing a number by trial division
To decide whether a number is prime, you hunt for a factor other than and . Find even one and is composite; find none and is prime. The direct method is trial division: try the candidate divisors in turn and watch for a clean division. You do not need to test every number below , and you do not need long division either. That is because the divisibility rules from the last lesson do most of the work.
Test the candidates in increasing order, , and lean on the rules you already know:
- Try : is the last digit even? If yes (and ), then is composite.
- Try : does the digit sum come out a multiple of ? If yes (and ), then is composite.
- Try : does it end in or ? If yes (and ), then is composite.
- Try , then the next candidates, dividing to check, until either a factor appears or you reach the stopping point in the next section.
You can skip every even candidate after , since an even divisor would make even and you have already checked . You can also skip multiples of after , so in practice you test , the primes themselves. A few small divisors are enough to settle even a fairly large number. The explanation is the stopping rule, which is the heart of the method.
The stopping rule: when can you quit?
Testing divisors one by one could go on a long time. The key shortcut is that you can stop early: once a candidate divisor grows large enough that passes , you are done. If nothing has divided by the time you reach that point, is prime. The reason is a fact about how factors come in pairs.
Watch the factors of do it. They arrive two at a time: with , with , with , with , and with . Every one of those pairs has a partner of or less, and is the number whose square is . Those six numbers, through , account for every factor pair has. A divisor above could only be the larger partner of a pair you already caught by its smaller one.
In plain terms: keep testing divisors only while . As soon as passes , stop.
The pairing that showed you is the whole reason, and it holds for every number. Whenever a number divides , it arrives with a partner: multiply the two and you get back. One of that pair is never larger than the value whose square is , because two partners both above it would already multiply past . So a search that tries every candidate up to that point, without finding one that divides , has already ruled out every possible pair, and must be prime.
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 , which settles it:
So is composite. A number can look prime at a glance and still hide a factor; the digit-sum test for catches many that the eye misses.
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, even though it can look prime at a glance. 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. Nothing divided , so it is prime.
The Sieve of Eratosthenes
To find all the primes up to some limit at once, there is a method faster than testing each number on its own. That method has been known since antiquity as the Sieve of Eratosthenes (a way to find every prime up to a limit by crossing out multiples). The idea is to start with every number and strain out the composites, leaving the primes behind. A sieve does the same, straining out what you do not want.
Write the whole numbers from up to your limit. Then repeat one move:
- Circle the smallest number not yet crossed out. It is prime (nothing below it divided it, or it would already be crossed out).
- Cross out every larger multiple of that number. They are all composite, since they have it as a factor.
The first prime is , so circle it and cross out . The next surviving number is , so circle it and cross out . Then , then , and so on. By the stopping rule, once the circled prime times itself passes your limit, everything still standing is prime and you are finished.