Prime Counting Function Calculator
This prime counting calculator tells you exactly how many prime numbers exist up to and including any whole number you choose, the value mathematicians call pi(n). Primes, the numbers only divisible by themselves and one, thin out as numbers grow larger but never stop appearing, and there is no simple algebraic formula that predicts exactly how many exist below a given point. To get an exact answer you have to count them, which is what this tool does. Enter an upper limit n of up to 2,000,000 and the calculator runs a sieve of Eratosthenes, working through every number in that range and marking off multiples to identify every prime, before returning three results: the total count of primes less than or equal to n, the largest prime found within that range, and the upper limit you entered for reference. For example, entering 100 returns 25 primes, with 97 the largest. The two million ceiling keeps the sieve fast and light enough to run instantly in your browser rather than needing a server. For a quick sense check on bigger ranges, the prime number theorem suggests pi(n) is roughly n divided by the natural logarithm of n, though this calculator always gives you the exact count rather than an approximation. It is a handy tool for students, programmers and anyone curious about how primes are distributed across the number line.
The formula
pi(n) counts the primes p with p less than or equal to n. There is no simple closed formula, so the calculator builds a sieve of Eratosthenes and counts. For scale, the prime number theorem says pi(n) is roughly n divided by the natural logarithm of n.
Worked example
Up to 100 the primes are 2, 3, 5, 7, 11 and so on up to 97, and there are 25 of them, so pi(100) = 25 with 97 the largest. Enter 100 to confirm.
Frequently asked questions
What is the prime counting function?
pi(n) is the number of primes less than or equal to n. For example pi(10) = 4, counting 2, 3, 5 and 7.
Is there a formula for pi(n)?
No simple closed form. The prime number theorem approximates it as n over the natural log of n, but exact counts use a sieve.
Why the two million limit?
The sieve needs an array of that size. Two million keeps it fast and memory light in the browser.
Who this calculator is for
This calculator is for students, programmers and anyone exploring number theory.
What this calculator assumes
- You enter a whole number within the stated range.
- The exact integer algorithm is used.
- Very large results are shown grouped for readability.
Formula and sources
Related calculators
- Prime Factorization Calculator: break a number into prime factors.
- LCM Calculator: lowest common multiple.
- GCF Calculator: greatest common factor.