Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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.

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 making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2016-10-23 10:59 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.