Procedure
Primality by trial division up to
Arithmetic • Number System • Prime Numbers
Statement
An integer is prime if and only if no prime with divides it. The bound is forced: if with , then , so every composite has a prime factor not exceeding .
How to use it
- 1Find the largest integer whose square does not exceed , then test only the primes up to it.
- 2Work upwards through and stop at the first divisor: it settles the matter as composite.
- 3For any the only tests needed are , because .
Worked example
Is prime?
Step-by-step
- 1, so test the primes
Why: Only a prime factor at or below could exist, and lies between and .
- 2is odd; ; it does not end in or ;
Why: Each test is a divisibility rule or one short division, and none leaves remainder .
- 3No prime up to divides , so is prime
Answer
Yes, is prime
Watch out
The bound applies to PRIME divisors: testing composite divisors is wasted work, and stopping below proves nothing at all. Testing every integer up to is correct but far slower, and under time pressure that difference is the whole point.
Builds on
Also known as
trial division, primality test, test divisors up to the square root, is n prime, square root bound on a factor, check for primality