The prime counting function $ \pi (x) \approx \dfrac {x} {\ln(x-1)} $. This function returns the number of primes less than $x$.
Note: $x-1$ gives a better estimate than $x$.
How to find $x$ given $ \pi(x) $ ?
The prime counting function $ \pi (x) \approx \dfrac {x} {\ln(x-1)} $. This function returns the number of primes less than $x$.
Note: $x-1$ gives a better estimate than $x$.
How to find $x$ given $ \pi(x) $ ?
Instead of an analytical Expression or 1-Step Approximation use a Fixed Point Iteration that converges relatively fast to the Inverse of x/ln(x).
8 Iterations yield the Result e.g. x = 4_210_563_857 for y = 190_000_000:
public static double PI_INVERSE(double y) {
double xOld = 0;
double x = y*Math.Log(y);
const double maxDiff = 0.5;
for (; x - xOld > maxDiff;) { //strictly monotonous
xOld = x;
x = y*Math.Log(x);
}
return x;
}