Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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, which has the first 1.4 billion primes on file.

Comment on Re^2: is it prime?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-08-20 18:59 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (121 votes), past polls