1.1.8 · D4Arithmetic & Number Systems

Exercises — Prime numbers — Sieve of Eratosthenes, primality testing

2,225 words10 min readBack to topic

Before we begin, three tiny reminders so every symbol on this page is already "earned":


L1 — Recognition

Problem 1.1

Which of these are prime? .

Recall Solution

Apply the definition: a prime has exactly two distinct divisors, and itself.

  • → only one divisor. Neither prime nor composite.
  • → divisors . Prime (the only even prime).
  • → divisor . Composite.
  • ; test : odd, and not divisible by . Prime.
  • Composite. Primes: .

Problem 1.2

State the smallest prime greater than .

Recall Solution

Walk upward from :

  • (digit sum , divisible by ).
  • even. : , test → none divide. is prime. Answer: .

L2 — Application

Problem 2.1

Use trial division to decide whether is prime. Show which divisors you test and why you stop where you stop.

Recall Solution

WHY : if with , then . So a divisor above always has a partner below — testing up to is enough. Test primes : .

  • : is odd. No.
  • : digit sum , not a multiple of . No.
  • : ends in . No.
  • : , remainder . No.
  • : alternating sum , not or . No.
  • : , remainder . No. No divisor is prime.

Problem 2.2

Sieve of Eratosthenes up to . List which starting square each prime crosses from, and give the survivors.

Recall Solution

, so we only sieve with primes where , i.e. .

  • : cross from : .
  • : cross from : (some already gone — that's fine).
  • : stop. Survivors: — the primes below . ✓

L3 — Analysis

Problem 3.1

The figure below shows the "smaller-factor lives below " idea for . Using it, explain in words why testing beyond can never find a new divisor, then list all factor pairs of to confirm.

Figure — Prime numbers — Sieve of Eratosthenes, primality testing
Recall Solution

Look at the figure: the yellow curve is area line; the dashed diagonal marks where . Every factor pair with sits with to the left of and to the right. The pairs mirror around . Factor pairs of : The smaller entries are — all . Every larger factor () is just the partner of a smaller one already found. So scanning past re-discovers nothing new. That is exactly why trial division stops at . ✓

Problem 3.2

Find the smallest composite number that is not caught by "test only the primes ". Prove it survives that partial test.

Recall Solution

A composite survives "" only if its smallest prime factor is . The smallest such number is . Check it dodges the partial test:

  • is odd ⇒ passes "".
  • digit sum , not a multiple of ⇒ passes "".
  • ends in ⇒ passes "". Yet is composite. Any smaller composite () has a factor of or and would be caught. Answer: .

L4 — Synthesis

Problem 4.1

Two numbers: and . Using prime factorisations (not brute force), find and .

Recall Solution

Compute the raw values: , . By the Fundamental Theorem of Arithmetic, each number is a unique bag of prime factors:

  • GCD = product of primes in both bags, each to the smaller power: common primes are
  • LCM = every prime that appears in either bag, each to the larger power: Sanity check: . ✓

Problem 4.2

Estimate how many division operations a sieve up to saves versus starting each prime's crossing at instead of , for the prime . (Count the extra multiples wrongly crossed.)

Recall Solution

Starting at we would visit multiples up to (exclusive) before reaching the first genuinely-new one. These are for : that's 5 multiples. Every one was already crossed by a smaller prime (), so all crossings are wasted. Correct start is ; the first new multiple is . Wasted crossings avoided for : . ✓ (This is the general saving: redundant multiples per prime.)


L5 — Mastery

Problem 5.1

A repunit is the number made of ones in a row: , , . Prove that for every even with , the repunit is composite. (Handle the boundary case separately.)

Recall Solution

First, the boundary . is prime — so the claim is deliberately stated for , not all even . We exclude on purpose because it is the one even repunit that stays prime. Keep this in mind: "even " alone is not enough; we need .

Now the main case, even. Write with . The trick is to read the string of ones two digits at a time from the right, because is itself two ones.

Deriving the grouping concretely. Take . Split it into two-digit blocks from the right: . The left block sits in the "hundreds" place, so its value is ; the right block is just . Hence For the same splitting gives three blocks: In general, grouping into two-digit blocks , block number (counting from the right, ) carries the value . Adding the blocks: This factorisation is not "asserted from grouping" — it is exactly the place-value expansion, where each two-digit block of ones is worth scaled by a power of .

Conclusion. The bracket is a whole number and, since , it is at least . So is a product of two factors each bigger than is composite for every even . ✓ Example check: ; . Both composite.

Problem 5.2

A student claims: "Every number ending in or is prime." Refute it by giving a composite ending in each of those four digits, and one prime ending in each, so no case is left uncovered.

Recall Solution

Numbers ending in are handled by divisibility by or , so the interesting last digits are exactly . For each we must show both outcomes are possible — the last digit alone decides nothing.

last digit a composite a prime

Every one of the four ending-digit cases produces both a composite and a prime ⇒ the last digit carries no primality information. The claim is false. ✓

Problem 5.3

Using the bound, what is the largest prime you must trial-divide by to certify that is prime? Then certify it.

Recall Solution

, so the largest divisor to test is ; the largest prime is . Test primes :

  • even? no. digit sum , not . ends in , not .
  • : , rem . : alt sum , no. : , rem . : , rem . : , rem . : , rem . : , rem . : , rem . : , rem . : , rem . : , rem . No prime divides is prime.Largest prime tested: .

Recall Master summary — say it aloud
  • Prime = exactly two divisors; is neither.
  • Trial-divide only up to — the small factor always hides below the square root.
  • Sieve: cross multiples from , stop when .
  • Factorisation is unique ⇒ GCD uses smaller exponents, LCM uses larger.
  • Last digit alone never decides primality; and "even " repunits are composite only from .

Connections