Hello,(adsbygoogle = window.adsbygoogle || []).push({});

I'm looking for some good and fast algorithm to find all prime numbers less than a given number. I've got a simple program which finds all primes less than any number, but once n gets above 500,000 it takes much too long. (More than 5 minutes. Just up to 100000 it takes about 7 seconds.)

My method is simply sieve of Eratosthenes, divide each number by every consecutive and so on. What'd be your method?

Thanks,

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Fast algorithm for finding number of p less than n

**Physics Forums | Science Articles, Homework Help, Discussion**