Post Reply 
Fast prime finder??
07-29-2016, 02:50 AM
Post: #2
RE: Fast prime finder??
(07-28-2016 08:22 PM)Namir Wrote:  Hi All,

I am looking for the fastest algorithm to:

1) Determine if a number is a prime.
2) Find the next prime after a given number.

I plan to include the best answer in my HHC2016 presentation.

The keyword here is fast computational-wise.

Thanks!

Namir

This problem has been studied a lot, and the algorithms are well known. I'm not sure what you are aiming at: calculator code? any code? or just the algorithm? what magnitude of numbers do you need to test?
I wrote a few routines for newRPL that use a bitmap table for primes <120000. This allows you to both test for primality and get the next prime number (given a number <120000) extremely fast, which speeds up the brute force primality test for numbers up to 120000^2 = 1.44e10.
For larger numbers it falls back to brute force (test the remainder after division by every prime <= sqrt(N)).
In the future it will use Miller-Rabin or similar pseudo-prime algorithm for large numbers, but that's not implemented yet.

I recently tested the number 9,999,999,967 per this thread:
http://www.hpmuseum.org/forum/thread-6567.html

Since it's < 1.44e10 I got a very fast result at 0.057s.

While the tables are encoded in a creative way, there's nothing to be proud of, as it's basically a brute force primality test accelerated with look-up tables.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Fast prime finder?? - Namir - 07-28-2016, 08:22 PM
RE: Fast prime finder?? - Claudio L. - 07-29-2016 02:50 AM
RE: Fast prime finder?? - Namir - 07-29-2016, 07:27 AM
RE: Fast prime finder?? - Namir - 07-29-2016, 12:03 PM
RE: Fast prime finder?? - ttw - 08-01-2016, 09:59 PM
RE: Fast prime finder?? - Namir - 08-02-2016, 12:01 AM
RE: Fast prime finder?? - ttw - 08-03-2016, 08:36 AM
RE: Fast prime finder?? - Namir - 08-03-2016, 11:07 AM
RE: Fast prime finder?? - Namir - 08-03-2016, 11:50 AM
RE: Fast prime finder?? - Namir - 08-04-2016, 11:54 PM
RE: Fast prime finder?? - Claudio L. - 08-05-2016, 12:46 AM



User(s) browsing this thread: 1 Guest(s)