Question bank — Prime numbers — Sieve of Eratosthenes, primality testing
Prerequisites and links used below: the parent topic, Fundamental Theorem of Arithmetic, Divisibility rules, GCD and LCM, Modular arithmetic, Time complexity Big-O, Factorisation.

Look at the red strip on the right: has no wider rectangle, so it is prime. The black and grids on the left show and folding neatly into rectangles — that folding is what "composite" means. Every "Spot the error" and "Why" item below is really about which numbers can and cannot fold.

The strip above is the Sieve in one glance: knocks down its multiples, then , then ; the red squares that never get knocked down are exactly the primes. Notice each prime starts crossing at its square (the red-outlined cell) — everything smaller was already gone.
True or false — justify
Recall Every prime greater than 2 is odd.
True — if a prime were even it would be divisible by , giving a third divisor (), so it could not be prime. Thus is the only even prime. ::: True; is the lone even prime, every other even number has as a proper divisor.
Recall The product of two primes is always composite.
True — has the divisor with , which is exactly the definition of composite. Such a number (a product of exactly two primes) is called a semiprime, e.g. ; see Factorisation. ::: True; the factors and are proper divisors, so the product (a semiprime) is composite by definition.
Recall If a number is not divisible by
, , or , it must be prime. False — you must trial-divide up to (floor = round down, defined above). and dodge yet are composite (see Divisibility rules for why small tests aren't enough). ::: False; and pass the tests but are composite.
Recall There is a largest prime number.
False — Euclid's argument: multiply all known primes, add ; the result is divisible by no listed prime, so a new prime must exist. Primes are infinite. ::: False; primes are infinite (Euclid: forces a prime outside any finite list).
Recall Two different primes can share a common factor greater than 1.
False — a prime's only divisors are and itself, so two distinct primes have ; they are coprime (see GCD and LCM). ::: False; distinct primes are coprime, their only shared divisor is .
Recall Every composite number has a prime factor.
True — this is guaranteed by the Fundamental Theorem of Arithmetic: every integer breaks into a product of primes, so the smallest divisor above must itself be prime. ::: True; the Fundamental Theorem of Arithmetic guarantees a prime factorisation, hence a prime factor.
Recall
for distinct primes implies . True — since and , the LCM absorbs the full product. This is the GCD and LCM identity applied to coprime primes. ::: True; and force .
Spot the error
Two flavours live here: a logical mistake (the claim is false) and a performance-tuning tip (the claim is true but wasteful). Each reveal says which kind it is, so you never confuse "wrong" with "slow."
Recall "1 is prime because it is divisible only by 1 and itself." — logical mistake?
Logical mistake. The definition demands exactly two distinct divisors. For , "" and "itself" coincide — only one divisor exists. Admitting would also wreck unique factorisation (). ::: Logical mistake: has only one distinct divisor, not two, and allowing it breaks uniqueness in the Fundamental Theorem of Arithmetic.
Recall "To test if
is prime, stop dividing once you pass a few small numbers with no hit." — logical mistake? Logical mistake. You must reach . If with , then , so a missed divisor can hide right up to the square root — e.g. needs testing up to . ::: Logical mistake: the smaller factor can be as large as ; stopping early misses divisors like in .
Recall "In the Sieve, start crossing multiples of
from ." — logical mistake or tuning tip? Tuning tip, not a mistake. The result is correct, merely wasteful: every multiple with was already crossed while sieving the smaller prime . The first new multiple is . ::: Tuning tip (not wrong, just slow): multiples below are already crossed by smaller primes, so starting at saves work.
Recall "Keep sieving with every prime up to
to be safe." — logical mistake or tuning tip? Tuning tip, not a mistake. It still finds the right primes, just does needless work: any composite has a prime factor , so once nothing new can be crossed (see Time complexity Big-O). ::: Tuning tip (correct but slow): stop at ; every surviving number above that is automatically prime.
Recall "
trial division and the sieve's start are two separate tricks." — logical mistake? Logical mistake (a misconception). They are the same fact wearing two hats: the smaller factor of any pair sits below . Trial division reads it as "test to "; the sieve reads it as "start at and stop at ." ::: Logical mistake: both come from one fact — the small factor of a pair is .
Recall "
and negative numbers can be prime if they have few factors." — logical mistake? Logical mistake. Primality is defined only for natural numbers . is divisible by everything, and negatives fall outside the definition entirely. ::: Logical mistake: the definition requires ; , , and negatives are excluded by convention.
Why questions
Recall Why does excluding
from the primes make factorisation unique? If counted as prime, you could pad any factorisation with extra s (), so "the" prime factorisation would no longer be single. Excluding pins it down. ::: Because could be multiplied in endlessly, destroying the uniqueness the Fundamental Theorem of Arithmetic promises.
Recall Why is
special among the primes? It is the only even prime; every larger even number carries as a proper divisor. Its evenness makes it the one prime that breaks the "all primes are odd" pattern. ::: Because it is the sole even prime — all other evens are composite (divisible by ).
Recall Why do primes matter to
Modular arithmetic? When the modulus is prime, every nonzero remainder has a multiplicative inverse, so division "works" — a property composite moduli lack. Primes give the cleanest arithmetic systems. ::: Because a prime modulus makes every nonzero element invertible, unlike composite moduli.
Recall Why does the sieve remove composites rather than find primes directly?
Composites are the numbers that fold into a rectangle (see the first figure) — easy to generate as multiples. Removing all of them leaves exactly the numbers that are not rectangles, i.e. the primes, without testing each one. ::: Because multiples (the "rectangle" numbers) are easy to list and cross out; whatever survives must be prime.
Recall Why does trial division cost
and not ? We only test divisors up to , and any divisor above it has a partner below it. So the number of checks scales with — see Time complexity Big-O. ::: Because only divisors up to need testing, giving checks instead of .
Edge cases
Recall Is
handled correctly by "test only odd divisors" primality code? itself must be special-cased as prime before skipping evens; otherwise the shortcut that assumes odd inputs would misclassify it. ::: must be declared prime up front; the odd-only skip assumes the input is already known not to be .
Recall What does the sieve do for
? Nothing — the candidate list is empty (there is no integer between and ), so it correctly returns no primes, matching the fact that no primes exist . ::: The list is empty, correctly yielding no primes since none exist .
Recall What does the sieve do for
? Nothing survives — the list is empty, so there are no primes , which is correct since is not prime. ::: The candidate list is empty, correctly yielding no primes (since is not prime).
Recall For
, does the sieve ever cross anything out? No — but , so the loop stops immediately and survives as the only prime. This is the smallest working case. ::: No crossing occurs (); survives, correctly the only prime .
Recall For
, what does the sieve do, and how does it extend the case? Again nothing gets crossed — has , so the loop halts on the very first prime. Both and survive, which is right since are the primes . It shows the pattern from holds: while , every candidate is auto-prime. ::: Nothing is crossed (); both and survive, matching the primes and extending the pattern.
Recall Is a perfect square like
a boundary case for trial division? Yes — its factor pair is , so both factors equal . You must test up to and including , or you'd miss the equal-factor case. ::: Yes; means the divisor sits exactly at , so the loop must include .
Recall Can the smaller factor of a composite ever exceed
? No — if both factors exceeded , their product would exceed , a contradiction. That impossibility is the whole engine behind the bound. ::: No; two factors both above would multiply past , which is impossible.
Recall Is
(a prime squared) prime, and how many divisors has it? Composite, with exactly three divisors: , , and . It is the simplest composite that a naive "few small primes" check can miss when is not tiny. ::: Composite; it has three divisors (), so it is never prime for any prime .
Connections
- Fundamental Theorem of Arithmetic
- Divisibility rules
- GCD and LCM
- Modular arithmetic
- Time complexity Big-O
- Factorisation