Prime Number Calculator
Check if a number is prime, find the next prime, or list all primes up to any limit.
#p What is a Prime Number?
A prime number is any integer greater than 1 that has exactly two positive divisors: 1 and itself. The first few primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. The number 2 is the only even prime — every other even number is divisible by 2 and therefore composite. Numbers that are not prime (and not 1) are called composite numbers: they have at least one divisor between 1 and themselves.
Prime numbers are the fundamental building blocks of arithmetic. The Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed as a unique product of primes (its prime factorization). For example, 360 = 2³ × 3² × 5. This uniqueness property makes primes central to number theory, cryptography (RSA encryption relies on the difficulty of factoring large numbers into primes), computer science, and pure mathematics.
Testing primality efficiently is a classic computer science problem. The simplest method — trial division — checks all integers from 2 to √n. This works well for numbers up to a few million. For enormous numbers (hundreds of digits), probabilistic tests like Miller–Rabin or deterministic algorithms like AKS are used. This calculator uses trial division, optimized to check only odd divisors after ruling out evenness, giving O(√n) performance.
To generate all primes up to a limit, the Sieve of Eratosthenes is the classical algorithm: mark all integers, then iteratively cross out multiples of each prime starting from 2. It runs in O(N log log N) time and is highly practical for N up to 10 million on modern hardware. This calculator's List mode uses this approach for limits up to 10,000.