home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!pavo.csi.cam.ac.uk!gjm11
- From: gjm11@cus.cam.ac.uk (G.J. McCaughan)
- Newsgroups: sci.math
- Subject: Re: nth prime
- Message-ID: <1992Sep10.164133.27763@infodev.cam.ac.uk>
- Date: 10 Sep 92 16:41:33 GMT
- References: <1992Sep10.190905.10741@waikato.ac.nz>
- Sender: news@infodev.cam.ac.uk (USENET news)
- Organization: U of Cambridge, England
- Lines: 18
- Nntp-Posting-Host: apus.cus.cam.ac.uk
-
- In article <1992Sep10.190905.10741@waikato.ac.nz> bill@waikato.ac.nz writes:
-
- >Sorry to ask such a FAQ, but what's the quickest algorithm to
- >find the nth prime? Is it O(nlogn) or something else?
-
- I think there is no way to get p_n exactly that's much better than
- the good old sieve of Eratosthenes. So in sieving out multiples of 2
- you do n/2 things, and in [... er, we're suddenly working out the
- biggest prime less than n. This is of equal complexity...] total
- we do n(1/2+1/3+...+1/p) things, where p is the biggest prime less
- than root(n). Now it's well known that the series there comes to
- about log log root(n). So the time for "primes up to n" is about
- n log log n, and so the time for "nth prime" is about
- (n log n) log log (n log n), which is about n log n log log n.
- As I say, I don't think you can do much better than this.
- --
- Gareth McCaughan Dept. of Pure Mathematics & Mathematical Statistics,
- gjm11@cus.cam.ac.uk Cambridge University, England. [Research student]
-