I am writing a prime number sieve in software. I want to be able to return the first $n$ primes, where $n$ is an argument to the sieve function.
In order to do this efficiently, I would like to be able to allocate an array of integers that I know can hold the first $n$ primes at a minimum. This means the sieve will be just big enough, or too big, but never too small.
What I need is to reverse the prime counting function: instead of computing "number of primes below a value" I need "value equal to or greater than prime #n".
For example: if I ask for the first ten primes, I should be able to compute that $f(10)$ is some value equal to or greater than $29$. It does not need to be a tight bound, but should not be wildly greater than its bound (i.e. $f(n)$ should not evaluate to $n^2$).
Starting with Wikipedia's prime-counting article, I see that:
$$ \Pi(n) < {1.25506n \over \ln(n)} $$
Great! This inequality means that if I can find n, I only have to sieve once without copying potentially millions of numbers around in memory more than once.
$\Pi(n)$ is the argument to my sieve function: it is the number of primes I am trying to find. $n$ is unknown: it is the size of the sieve I need to use. If I restate the above inequality as an equality relating the number of primes $q$ with the sieve size $n$, I get:
$$ q = {1.25506n \over \ln(n)} $$
$$ 1.25506n = q \ln(n) $$
$$ n = {q \ln(n) \over 1.25506} $$
$$ {n \over \ln(n)} = {q \over 1.25506} $$
Since $q$ is known and I am trying to find $n$, I need to isolate $n$ and state it in terms of $q$ and constants. However, I am not sure how to get rid of the $\ln(n)$: any advice? This should be easily computable in Java, so preferably avoiding calculus or anything not in the java.lang.Math
class would be ideal. If there is a way to approximate this function while still holding the post-condition (sieve is guaranteed to be large enough to hold $n$ primes) that is acceptable as well.
Note: this is similar to, but not the same as, Inverse of prime counting function due to the specific requirements and help requested.