Is there any function to evaluate the number of prime numbers between [2, n]
?
For example, consider the following range: [2, 20]
. In this case the number of prime numbers between 2
and 20
is 8
: 2, 3, 5, 7, 11, 13, 17, 19
.
Therefore the function I'm looking for would return 8.
Also, is there any function to evaluate the number of prime numbers between [x, y]
?
Best Answer
There are some formulas but the best we have so far is only asymptotic estimates.
It is shown that if we denote with $\pi(n)$ the number of primes that do not exceed $n$ then the fraction
$$\frac{\pi(n)lnn}{n}$$ can be arbitrarily close to $1$.
This is the famous prime number theorem.