Welcome to OnlineConversion.com

Prime number calculator

Prime number calculator
by Thowllly on 06/18/03 at 14:59:13

I don't know if this has been mentioned before, but the prime number calculator is unnecessarily slow. I was going to check if 10,000,000,019 was a prime number, but it took so long that I gave up waiting. Two tips:

1. You don't have to try dividing by any even numbers, except the number 2 of course. Check for 2 first then start the loop at 3 and increase the variable I by 2 instead of 1 for every iteration.

2. You only have to check numbers up to the square root of the number being tested. (So for 10,000,000,019 you only have to test up to 100,000, not all the way up to 10,000,000,018 ). Calculate the square root before the loop, not in the loop...

Iím sure you already knew about these, Iím not trying to insult your intelligence with these obvious suggestions :)

Anyway, it would be nice to see these suggestions implemented so I can find out if that number is prime or not :) (Iím trying to find an 11 digit prime). There are of course lots of ways to do the test much faster, but the two I've mentioned are the simplest, I think...

(also, there is two divide (modulus) operations in the loop when one is enough)

Re: Prime number calculator
by Robert Fogt on 06/19/03 at 05:34:23

I have put that on my to-do list and I'll see what I can do.

Thanks for the feedback.

Re: Prime number calculator
by Robert Fogt on 06/22/03 at 23:38:50

I just finished updating the Prime Number calculator here:

And zoom, it is fast. †You can now check very large numbers in under a second.

10000000019 is a prime number.

Go Back | Archive Index


Did you find us useful?

Please consider supporting the site with a small donation.

click here for more information


BookMark Us

It may come in handy.

Check out our Conversion Software for Windows.

Can't find something?
Try searching.

Are you bored?
Try the Fun Stuff.

Was this site helpful?
Link to Us | Donate