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.
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\).
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\).