Primes and Composites
Learning goals
- Define prime and composite by counting a number's factors
- Explain why is neither prime nor composite
- Say why is the only even prime
- Test a number by trial division with the divisibility rules
- Stop testing once the divisor times itself passes the number
- 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 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 the rows come out even, 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 even, 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:
The word prime comes from the Latin for “first”, and the primes are first in the sense of being the simplest. They are the ones not built from smaller pieces. A composite number, as the name suggests, is “composed” of smaller factors.
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.
Why is excluded from the primes#
List the factors of . A factor of is a whole number that divides with no remainder. The only whole number that does this is , since and any larger number divides with a remainder. So the complete factor list of is just
a set with a single member. The definition of prime demands exactly two distinct factors, and supplies only one, so is not prime. It is not composite either, because composite means more than two factors, and one is fewer than two, not more. So sits outside both groups on its own.
The exclusion of is not a quirk of bookkeeping. Keeping out of the primes is what makes the primes behave as clean building blocks in the next lesson. If were prime, you could glue extra copies of it onto any factorization () and never get a single, settled answer. Leaving aside keeps each number’s set of prime building blocks unique.
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. That free gift of a arrives with every even number, which is what decides the general case.
Why is the only even prime#
First, itself is prime: its only factors are and , which is exactly two, so it qualifies.
Now watch one other even number, say . It ends in , so divides it and is a factor. The number already carried and as factors, and this is neither of them, so it is a third one. Three distinct factors is one more than a prime is allowed, so is composite.
Only two things about were used: it is even, and it is bigger than . So take any even number greater than . Being even means divides it, so is a factor. But already has and as factors, and since is larger than , this is a third, different one. With at least three distinct factors, is composite.
So every even number past is composite, 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 . So testing finds every pair there is. 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. For , you test (since ) and then consider , but , which is already past , so is the signal to stop. None of divided , so is prime. You confirmed a prime by trying just four small divisors.
The pairing that showed you is the whole reason, and it holds for every number.
Why you may stop once the divisor times itself passes #
Try it on with the divisor . The division gives , so the arrives holding a partner, and . Those two partners fall either side of the value whose square is , which sits between and . They are forced to: two partners both above it would multiply past , since even overshoots. So the smaller partner is the one a search meets first, and it is met while is still under .
Now the same reasoning with letters. Whenever a number divides , the division produces a partner. If , then
so and are a pair of factors whose product is . They always come together: find one and you have found the other.
Now compare the pair against the value where a number times itself equals . The two partners cannot both be larger than it, or their product would overshoot . So whichever of and is the smaller, call it , satisfies . The larger partner has no such bound: for the smaller is , and is far past .
Every composite number therefore has a factor small enough to meet before your trial divisor reaches the point where it times itself passes . Suppose you have tested every candidate up to there and none divided . Then no factor pair is left to find, so has no factor besides and , and is prime. Any factor past that point would drag in a partner you already tried and ruled out.
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.
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 below 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.
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?
Use the digit-sum rule for to clear out three of them quickly.
Each of those is a multiple of , so composite. For : it is odd, and its digit sum is not a multiple of . The number does not end in or , and ends the search. So is prime.