Prime numbers and reversible primes
Learn trial division, the sieve of Eratosthenes and digit reversal using small, verifiable examples.
Core concepts and method
A prime is an integer greater than 1 with exactly two positive divisors: 1 and itself. If n is composite, at least one of its factors is no greater than √n. This makes trial division much faster than checking every possible divisor.
For many queries up to a known bound N, make a Boolean array indexed from 0 to N. Mark 0 and 1 as nonprime. For each remaining prime p with p² ≤ N, mark p², p²+p, p²+2p, … as composite. Smaller multiples already have a smaller prime factor.
A reversible prime test has two independent stages: check the original number, reverse its decimal digits, then check the result. Decide whether palindromic primes count by reading the exact question.
Worked example
Find the two-digit primes between 10 and 40 whose reversals are also prime.
- The primes are 11, 13, 17, 19, 23, 29, 31 and 37. Test divisibility only by primes up to the square root of each candidate.
- Reverse the digits: 11, 31, 71, 91, 32, 92, 13 and 73. Reject 91 = 7 × 13, and reject both even results.
- The qualifying original numbers are 11, 13, 17, 31 and 37. There are five if palindromes are allowed, four if they must be distinct from their reversals.
Try it yourself
Which of 47, 53 and 59 have prime reversals?
Show a hint
Reverse each number, then test 2, 3, 5 and 7 when needed.
Check your reasoning
47 reverses to 74 (even); 53 reverses to 35 (5 × 7); 59 reverses to 95 (5 × 19). None qualifies.
Practice the technique
These competition questions use related mathematical ideas. You can check your answers as a guest; sign in to save your progress.
- Reversible primes · easy · 25 min
- Prime beyond the milestone · easy · 25 min
- Prime digits checksum · medium · 50 min
About the editorial approach · Report a mistake in this lesson