Intuition Why this page exists
The parent note gave you the two tools: trial division (test one number) and the Sieve (harvest all primes up to N ). Here we drag those tools through every kind of input they can meet — small, big, "obviously prime", sneaky composites, edge cases like 0 and 1 , and a real-world twist. Nothing on the exam should surprise you after this.
Before we start, one reminder of the notation we lean on, built from zero:
Definition The symbols we will use
n ::: the natural number we are testing.
p ::: a prime number (from the parent definition: p > 1 with only divisors 1 and p ). We reuse p whenever we speak about a prime in general.
k ::: a generic whole-number multiplier — a stand-in for "any integer", used when we write things like "0 = 0 × k ".
⌊ x ⌋ ::: the floor — "round down to the nearest whole number". Picture a number line; ⌊ 9.8 ⌋ = 9 means "the last integer you pass on the way up to 9.8 ".
n ::: the side length of a square whose area is n . If n = a × b is a rectangle, n is the side of the square with the same area — and one of a , b must be ≤ that side (the smaller-factor bound).
d ∣ n ::: read "d divides n " — n ÷ d leaves remainder 0 .
τ ( n ) ::: the divisor-count function — "how many positive whole numbers divide n ". E.g. τ ( 6 ) = 4 because 1 , 2 , 3 , 6 all divide 6 .
prime divisors in trial division?
In every example below we try only prime d (2 , 3 , 5 , 7 , 11 , … ) and skip composites like 4 , 6 , 9 . Why is that safe? If a composite d divided n , then every prime factor of d would divide n too — and those primes are smaller , so we'd have caught one already. Example: if 4 ∣ n then 2 ∣ n , already tested. So checking primes catches all possible divisors. This shortcut leans on the Fundamental Theorem of Arithmetic .
Every case this topic can throw at you falls into one of these cells. The worked examples below are tagged with the cell they cover, and together they hit all of them .
Cell
Case class
What makes it tricky
Example
A
Degenerate input: n = 0 or n = 1
Definition edge — "neither prime nor composite"
Ex 1
B
Smallest primes n = 2 , 3
⌊ n ⌋ < 2 → no divisor to test
Ex 2
C
Genuine prime, mid-size
Must go all the way to n
Ex 3
D
Sneaky composite p × q , both odd
"Feels prime", small-prime tests miss it
Ex 4
E
Perfect square = p 2
The divisor sits exactly at n
Ex 5
F
Even / trivially composite
First test kills it
Ex 6
G
Full Sieve harvest up to N
Where to start/stop crossing
Ex 7
H
Real-world word problem
Translate → primality
Ex 8
I
Exam twist (count divisors / limiting)
Reason about structure , not brute force
Ex 9
0 prime? Is 1 prime?
Forecast: many students say "1 is prime, it's only divisible by itself." Pause and predict before reading.
Step 1 — Check the gate n > 1 . Why this step? The definition starts "a natural number greater than 1 ". Both 0 and 1 fail this gate immediately.
0 : not > 1 . And 0 = 0 × k for every whole-number multiplier k — it has infinitely many divisors. Not prime, not composite.
1 : not > 1 . Its only divisor is 1 itself — that is one divisor, but a prime needs exactly two distinct (1 and the number itself).
Step 2 — Confirm via the "rectangle" picture. Why this step? A prime can only be a 1 × p strip. 1 is a single dot — not even a strip of length ≥ 2 .
Verify: Both are neither prime nor composite . This is a convention , chosen so the Fundamental Theorem of Arithmetic stays clean: allowing 1 would let 6 = 2 ⋅ 3 = 1 ⋅ 2 ⋅ 3 = 1 ⋅ 1 ⋅ 2 ⋅ 3 , destroying uniqueness. ✓
2 prime? Is 3 prime?
Forecast: how many divisors do you even test for these? Guess.
Step 1 — Compute the bound. Why this step? Trial division only checks d = 2 , … , ⌊ n ⌋ .
2 ≈ 1.41 , so ⌊ 2 ⌋ = 1 .
3 ≈ 1.73 , so ⌊ 3 ⌋ = 1 .
Step 2 — Read the empty loop. Why this step? The test range is d = 2 up to 1 — that is an empty range . There is nothing to test .
Step 3 — Interpret "no divisor found". Why this step? If the loop finds no divisor, the number is prime. An empty loop finds none, so both pass automatically. This is exactly why 2 and 3 are the base primes the whole Sieve is built on.
Verify: 2 and 3 are prime. (2 is the only even prime — every other even number has 2 as a divisor.) ✓
149 prime?
Forecast: it's odd, doesn't end in 5 . Prime or hidden factor?
Step 1 — Bound. 149 ≈ 12.2 , so ⌊ 149 ⌋ = 12 . Why this step? Any factor pair a × b has a ≤ 149 < 13 , so we only need divisors up to 12 .
Step 2 — Test only the primes up to 12 : 2 , 3 , 5 , 7 , 11 . Why only primes? By the shortcut in the notation box, a composite divisor (like 4 , 6 , 8 , 9 , 10 ) would drag a smaller prime factor along, and we'd have caught that prime first. So primes alone cover every case. We use Divisibility rules to save arithmetic.
2 : 149 is odd → no.
3 : digit sum 1 + 4 + 9 = 14 , not a multiple of 3 → no.
5 : ends in 9 → no.
7 : 7 × 21 = 147 , remainder 2 → no.
11 : alternating sum 1 − 4 + 9 = 6 , not a multiple of 11 → no.
Step 3 — Stop at 11 . Why this step? Next prime is 13 , and 13 > 12 = ⌊ 149 ⌋ . A divisor ≥ 13 would need a partner ≤ 149/13 ≈ 11.5 < 13 — which we already ruled out. So we're done.
Verify: No divisor ≤ 12 . 149 is prime. ✓
This is the trap the parent warned about, made concrete.
The figure lays the candidate divisors 0 –20 on a number line. The dashed plum line marks 221 ≈ 14.9 . The teal dot at 13 is the smaller factor and the orange dot at 17 is the larger factor — notice 13 sits just left of the plum line and 17 sits right of it. The arrow shows exactly where a rushed "gut" test stops (after 11 ), one prime short of the divisor that would have unmasked 221 . Keep that picture in mind as we walk the steps.
221 prime?
Forecast: odd, not divisible by 3 (digit sum 5 ) or 5 . Gut says prime?
Step 1 — Bound. 221 ≈ 14.9 , so ⌊ 221 ⌋ = 14 . Why this step? We must test primes up to 14 : 2 , 3 , 5 , 7 , 11 , 13 .
Step 2 — Test the small ones (the ones the gut checks). Why only these primes? Same shortcut — composite divisors are covered by their prime factors. We reproduce the incomplete gut check to see where it stops.
2 : odd → no. 3 : digit sum 5 → no. 5 : ends 1 → no. 7 : 7 × 31 = 217 , rem 4 → no. 11 : alternating sum 1 − 2 + 2 = 1 , not a multiple of 11 → no.
Step 3 — Do NOT stop. Test 13 . Why this step? 13 ≤ 14 , so it's still in range (the teal dot in the figure) — this is the whole lesson. 13 × 17 = 221 . Found it.
Verify: 221 = 13 × 17 , composite . Sanity: 13 × 17 = 221 ✓. The factor pair is ( 13 , 17 ) — notice 13 < 221 < 17 : the smaller factor really does sit below the square root, exactly as the bound promises. ✓
169 prime?
Forecast: here the "hidden factor" lives exactly on the boundary. Where?
Step 1 — Bound. 169 = 13 exactly (a perfect square), so ⌊ 169 ⌋ = 13 . Why this step? When n = p 2 , the smaller and larger factor are equal — both sit precisely at n . If we tested only below the square root and used strict < , we'd miss it. The rule is ≤ ⌊ n ⌋ , which includes 13 .
Step 2 — Test up to and including 13 . Why this step? The primes 2 , 3 , 5 , 7 , 11 fail; 13 is the make-or-break.
Verify: 169 = 1 3 2 , composite . Lesson: never use a strict "< n " cutoff — perfect squares of primes are the counterexample. ✓
150 prime?
Forecast: you should reject this in one glance.
Step 1 — First test. Why this step? Always try the prime 2 first; even numbers die instantly.
150 ends in 0 → even → 2 ∣ 150 .
Verify: 150 = 2 × 75 , composite . We never needed the n machinery — one divisor is enough to disprove primality. (Full factorisation: 150 = 2 × 3 × 5 2 via the Fundamental Theorem of Arithmetic .) ✓
The Sieve isn't a per-number test — it paints out whole arithmetic ladders at once. Watch each colour.
Worked example Find every prime
≤ 50 with the Sieve.
Forecast: which primes p do you actually need to sieve with? Guess before Step 1.
Step 1 — Bound the callers. 50 ≈ 7.07 , so we only sieve with primes p ≤ 7 : that's 2 , 3 , 5 , 7 . Why this step? Any composite ≤ 50 has a prime factor ≤ 50 < 8 ; anything left un-crossed after p = 7 is automatically prime.
Step 2 — p = 2 , start at 2 2 = 4 . Why start at 4 ? Every multiple of 2 below 4 (just 2 ) is either prime itself or already handled. Cross 4 , 6 , 8 , … , 50 .
Step 3 — p = 3 , start at 3 2 = 9 . Why 9 ? 2 ⋅ 3 = 6 was already crossed by 2 ; the first new multiple of 3 is 3 ⋅ 3 = 9 . Cross 9 , 15 , 21 , 27 , 33 , 39 , 45 (evens like 12 already gone).
Step 4 — p = 5 , start at 5 2 = 25 . Cross 25 , 35 , 45 . (10 , 15 , 20 already gone.)
Step 5 — p = 7 , start at 7 2 = 49 . Cross 49 . Next prime is 11 , but 1 1 2 = 121 > 50 → stop .
Verify: Survivors are
2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47
That's 15 primes below 50 . Cross-check with the count of primes below 50 (known value 15 ). ✓
Worked example The locker gears
Two gears mesh: one has 221 teeth, the other 17 . They start aligned. After how many teeth-steps do the same two teeth meet again — and is either tooth-count prime?
Forecast: you smell an LCM problem. But there's a primality catch.
Step 1 — Translate. Why this step? "Same two teeth realign" = smallest number that is a multiple of both counts = lcm ( 221 , 17 ) .
Step 2 — Test 17 for primality. 17 ≈ 4.1 , test primes 2 , 3 : odd, digit sum 8 → both fail. 17 is prime.
Step 3 — Test/factor 221 . From Ex 4 , 221 = 13 × 17 . Why this matters? Because 17 ∣ 221 , the two tooth-counts share the factor 17 : g cd( 221 , 17 ) = 17 .
Step 4 — Compute the LCM. Why this formula? lcm ( a , b ) = g cd( a , b ) a ⋅ b .
lcm ( 221 , 17 ) = 17 221 × 17 = 221.
Verify: They realign after 221 teeth-steps. Makes sense: since 17 ∣ 221 , the small gear completes a whole number of turns (221/17 = 13 ) exactly when the big gear completes 1 turn. 17 is prime; 221 is composite. ✓
Worked example How many positive divisors does
360 have — and why does that instantly tell you it is not prime?
Forecast: guess the divisor count before computing.
Step 1 — Prime-factorise. Why this step? The Fundamental Theorem of Arithmetic says every number's divisor structure is fixed by its prime factorisation.
360 = 2 3 × 3 2 × 5 1 .
Step 2 — Apply the divisor-count formula. Why this formula? A divisor of 2 3 3 2 5 1 is any 2 a 3 b 5 c with 0 ≤ a ≤ 3 , 0 ≤ b ≤ 2 , 0 ≤ c ≤ 1 . The number of independent choices multiplies. Recall τ ( n ) counts divisors:
τ ( 360 ) = ( 3 + 1 ) ( 2 + 1 ) ( 1 + 1 ) = 4 × 3 × 2 = 24.
Step 3 — Read off the primality verdict. Why this step? A prime has exactly 2 divisors. 360 has 24 — nowhere close. In general τ ( n ) = 2 ⟺ n is prime.
Verify: 360 has 24 divisors; since 24 = 2 , it is composite. Spot-check the formula on a known prime: τ ( 13 ) = τ ( 1 3 1 ) = 1 + 1 = 2 ✓. ✓
Recall Which cell did each example patch?
0 and 1 ::: Cell A — fail the n > 1 gate; neither prime nor composite.
2 , 3 ::: Cell B — empty test range, auto-prime.
149 ::: Cell C — real prime, test primes up to ⌊ 149 ⌋ = 12 .
221 ::: Cell D — = 13 × 17 , the "don't stop early" trap.
169 ::: Cell E — = 1 3 2 , factor sits on n ; use ≤ , not < .
150 ::: Cell F — even, dies on first test.
Sieve to 50 ::: Cell G — sieve with 2 , 3 , 5 , 7 only; 15 primes.
Gears ::: Cell H — LCM = 221 because 17 ∣ 221 .
τ ( 360 ) = 24 ::: Cell I — divisor formula; = 2 so composite.
Mnemonic Scenario checklist
"Gate → Bound → March-to-root → include the root → one hit ends it."
Gate n > 1 ; bound ⌊ n ⌋ ; march all the way through the primes (Ex 4); include the boundary for squares (Ex 5); any single divisor proves composite (Ex 6).