8
$\begingroup$

Let $\pi(x)$ be the number of primes not greater than $x$.

Wikipedia article says that $\pi(10^{23}) = 1,925,320,391,606,803,968,923$.

The question is how to calculate $\pi(x)$ for large $x$ in a reasonable time? What algorithms do exist for that?

$\endgroup$
2
  • 3
    $\begingroup$ What's wrong with the ones given on the page? $\endgroup$
    – Noldorin
    Commented Jul 28, 2010 at 11:34
  • 2
    $\begingroup$ There is only one algorithm there. And I don't think it's possible to calculate $pi(10^{23})$ using it. Also there are no bounds on it's complexity. $\endgroup$
    – falagar
    Commented Jul 28, 2010 at 11:48

3 Answers 3

12
$\begingroup$

The most efficient prime counting algorithms currently known are all essentially optimizations of the method developed by Meissel in 1870, e.g. see the discussion here http://primes.utm.edu/howmany.shtml

$\endgroup$
1
$\begingroup$

You can use inclusion exclusion principle to get a boost over the Eratosthenes sieve

$\endgroup$
1
  • $\begingroup$ I'm not sure what do you mean, but Eratosthenes sieve is way too slow for numbers like 10^23. Could you provide an asymptotic complexity of your approach? $\endgroup$
    – falagar
    Commented Jul 28, 2010 at 11:23
1
$\begingroup$

The Sieve of Atkin is one of the fastest algorithm used to calculate $pi(x)$. The Wikipedia page says that its complexity is O(N/ log log N).

(edit)

I found a distributed computation project which was able to calculate $pi(4\times 10^{22})$, maybe it could be useful.

$\endgroup$
3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .