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

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 cooling their heels in the Monastery: (5)
As of 2015-11-28 12:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls