What this calculator does
This is a three-in-one prime numbers utility. It can (1) find the nth prime number, \(\text{Prime}[n] = p_n\); (2) test whether a given integer is prime and report its position in the prime sequence; and (3) list the first N prime numbers on demand. The first primes are 2, 3, 5, 7, 11, 13, 17, ... A prime number is an integer greater than 1 whose only positive divisors are 1 and itself.
Which prime number tool do you need?
- Prime number checker: whether a number is prime, with the previous and next prime.
- Prime number calculator: whether a number is prime and its smallest factor other than 1.
- Nth prime (this page): the nth prime, or a list of the first N primes.
- Prime factorization: the prime factors of a number, with a factor tree.
- Relatively prime: whether two numbers are coprime (no common factor other than 1).
How to use it
Pick a mode. In Nth prime mode, enter a 1-indexed position n (for example 100) and the calculator returns \(\text{Prime}[100] = 541\). In Primality check mode, enter any integer (for example 97) and it tells you whether the number is prime and, if so, its index n in the prime sequence. In List first N primes mode, enter how many primes you want and it returns the full comma-separated list along with the largest prime, \(\text{Prime}[N]\).
The formula explained
The primality test works by trial division: a number p is prime when no integer divisor exists between 2 and the square root of p.
$$\text{N is prime} \iff \text{N} \ge 2 \;\wedge\; \nexists\, d \in \left[2,\;\sqrt{\text{N}}\,\right]: d \mid \text{N}$$
We only need to test odd divisors d (after handling 2) while \(d \cdot d \le p\), which is fast and avoids floating-point error. The nth prime is found by scanning candidates 2, 3, 4, ... counting each prime until the count reaches n. The prime index of a prime m equals \(\pi(m)\), the number of primes less than or equal to m.
Worked example
Test 97. It is odd, so we try d = 3, 5, 7, 9 (since \(9^2 = 81 \le 97\) but \(11^2 = 121 > 97\)). None divide 97 evenly, so 97 is prime. Counting primes up to 97 gives \(2, 3, 5, \ldots, 97 = 25\) primes, so 97 is the 25th prime: \(\text{primeIndex} = 25\).
Prime Number Reference: First 25 Primes and Index Checkpoints
The index \(n\) is the position of a prime in the increasing sequence of primes, so \(p_n\) is the \(n\)-th prime. The table lists the first 25 primes.
| n | pn | n | pn | n | pn | n | pn | n | pn |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 6 | 13 | 11 | 31 | 16 | 53 | 21 | 73 |
| 2 | 3 | 7 | 17 | 12 | 37 | 17 | 59 | 22 | 79 |
| 3 | 5 | 8 | 19 | 13 | 41 | 18 | 61 | 23 | 83 |
| 4 | 7 | 9 | 23 | 14 | 43 | 19 | 67 | 24 | 89 |
| 5 | 11 | 10 | 29 | 15 | 47 | 20 | 71 | 25 | 97 |
Index checkpoints
| Statement | Value | Meaning |
|---|---|---|
| \(p_{100}\) | 541 | The 100th prime is 541 |
| \(p_{168}\) | 997 | The 168th prime is 997, the largest prime below 1000 |
| \(p_{1000}\) | 7919 | The 1000th prime is 7919 |
| \(\pi(10)\) | 4 | Primes up to 10: 2, 3, 5, 7 |
| \(\pi(100)\) | 25 | 25 primes up to 100 (the last is 97) |
| \(\pi(1000)\) | 168 | 168 primes up to 1000 |
| \(\pi(10000)\) | 1229 | 1229 primes up to 10,000 |
Note the link between the two notations: if \(p\) is prime, then \(\pi(p) = n\) exactly when \(p = p_n\). For example, \(\pi(997) = 168\) and \(p_{168} = 997\).
Prime Number Terms Explained
- Prime: a whole number greater than 1 whose only positive divisors are 1 and itself (for example 2, 3, 5, 7, 11).
- Composite: a whole number greater than 1 that has at least one divisor other than 1 and itself (for example 4, 6, 9, 15).
- 1 is special: the number 1 is neither prime nor composite. It has only one positive divisor, itself.
- 2 is the only even prime: every other even number is divisible by 2 and is therefore composite.
- Prime index (position) n: the rank of a prime in the ordered list of primes. 2 has index 1, 3 has index 2, 5 has index 3, and so on, so \(p_n\) denotes the \(n\)-th prime.
- Prime-counting function \(\pi(x)\): the number of primes less than or equal to \(x\). For example \(\pi(10) = 4\) and \(\pi(100) = 25\).
- Trial division: a primality test that tries dividing \(p\) by each integer \(d\) from 2 up to \(\sqrt{p}\). If none divides \(p\) evenly, \(p\) is prime. Checking only up to \(\sqrt{p}\) is enough because any factor pair has one member at most \(\sqrt{p}\).
- Coprime: two integers are coprime (relatively prime) if their greatest common divisor is 1. Two different primes are always coprime, but coprime numbers need not be prime (8 and 15 are coprime).
- Twin primes: a pair of primes that differ by 2, such as (3, 5), (11, 13), (17, 19), (29, 31) and (41, 43).
FAQ
Is 1 a prime number? No. By definition a prime must be greater than 1, so 1 is neither prime nor composite.
What is the only even prime? 2 is the only even prime; every other even number is divisible by 2.
What is the 100th prime? \(\text{Prime}[100] = 541\). Other checkpoints: \(\text{Prime}[10] = 29\), \(\text{Prime}[25] = 97\), \(\text{Prime}[50] = 229\), \(\text{Prime}[223] = 1409\).