Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: is it prime?

by JavaFan (Canon)
on May 06, 2012 at 15:12 UTC ( #969149=note: print w/ replies, xml ) Need Help??


in reply to Re: is it prime?
in thread is it prime?

One speedy way is to use the Sieve of Eratosthenes.
It's speedy if you want all primes below a certain number, or if you need to determine primality of "a lot of" numbers, but it isn't for checking a single number.

Checking all the possible divisors can be done in O(√N) (throw in a factor of O(log n) to do the division if you have really big numbers). However, just initializing the sieve will take you Ω(N) time. And then you still have to do the work: Ω(N/pi) for the ith prime.

The fastest way is probably just to use bigprimes.net, which has the first 1.4 billion primes on file.


Comment on Re^2: is it prime?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2014-07-31 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls