Prime Number List & Checker
List every prime number in a range (Sieve of Eratosthenes), or check whether a single number is prime — instant results.
1,072 views
Range too large — enter at most 1,000,000.
0 Primes Found
How It Works
The tool switches between two different algorithms, each suited to a different question. List mode finds every prime up to a limit using the Sieve of Eratosthenes, one of the oldest algorithms still in everyday use (attributed to the Greek mathematician Eratosthenes, 3rd century BC). Starting from 2, it marks off every multiple of 2 as composite, then moves to the next unmarked number (3) and marks off all its multiples, then the next unmarked number (5), and so on. Whatever survives unmarked once you reach the square root of the limit is prime. For a small example: to sieve up to 30, cross out multiples of 2 (4,6,8,…), then multiples of 3 (6,9,12,…, some already crossed), then multiples of 5 (10,15,…) — since 5×5=25 ≤ 30 but 7×7=49 > 30, you can stop there; whatever remains — 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 — is the complete list. This runs in O(n log log n) time, meaning it stays fast even as the range grows into the hundreds of thousands.
Check mode answers a different question — is this one specific number prime? — using trial division up to the square root. To test whether n is prime, it is enough to check for divisors from 2 up to √n. The reasoning: if n = a × b with both a and b greater than √n, then a × b would be greater than n, which is impossible. So at least one of the two factors must be √n or smaller, and it will be found before the loop finishes. Example: to check 97, you only need to test divisibility by 2, 3, 5, 7 (since 9² = 81 ≤ 97 but 10² = 100 > 97) — none divide evenly, so 97 is prime.
What to Know
The two modes exist because they trade off differently: the sieve is efficient for producing many primes at once but wastes memory and time if you only care about one number near a huge limit; trial division is efficient for a single check but far too slow if repeated for every number in a large range one at a time. Choosing the right one for the job is exactly why this tool offers both.
- 1 is excluded from the primes by definition and convention — it has only one divisor, not two, which would break the uniqueness of prime factorization if it were allowed in.
- 2 is the only even prime; every other even number is divisible by 2 and therefore composite.
- As numbers grow, primes become rarer on average, but never stop appearing — Euclid proved over two thousand years ago that there are infinitely many.
Frequently Asked Questions
What counts as a prime number?
A natural number greater than 1 with exactly two positive divisors: 1 and itself. 1 is not prime because it has only one divisor, and negative numbers are not considered prime or composite at all.
How large a range can I list?
Up to 1,000,000 — within that range the Sieve of Eratosthenes stays fast (its O(n log log n) complexity grows very slowly) and your browser stays responsive.
Why does trial division only need to check up to the square root?
If a number n has a divisor larger than √n, it must pair with a divisor smaller than √n (since their product equals n). So any factor pair always has at least one member at or below the square root — checking further is redundant.
Why not just use trial division for listing too?
You could, but it would be far slower: testing every number in a range individually up to its own square root does much more repeated work than the sieve, which eliminates multiples of each prime in one efficient pass across the whole range.
Are there infinitely many primes?
Yes — Euclid gave a proof around 300 BC: assume a finite list of all primes, multiply them together and add 1; the result is not divisible by any prime on the list, so either it is itself a new prime or it has a prime factor missing from the list. Either way, the list was incomplete.
Similar Tools
Report a Problem
Prime Number List & Checker
Comments
No comments yet — be the first to write one!