Ahs_58's blog

By Ahs_58, history, 5 years ago, In English

Is there any way to find prime number upto 10^9 or more in 1 second?

 
 
 
 
  • Vote: I like it
  • +13
  • Vote: I do not like it

»
5 years ago, # |
Rev. 5   Vote: I like it +30 Vote: I do not like it

Yes. It can be easily using Meisell-Lehmer algorithm to calculate the numbers of prime up to n in O(n^{2/3}).

or you can see F.Four Divisors.

»
5 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

If you want to enumerate all the primes upto 10^9 in 1 second, Segment Sieve of Eratosthenes plus Wheel Factorization will help a lot.

An example using primes 2, 3, 5, 7, 11, 13, code

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

segmented seive between 2 and n will may help you to find all prime up to range 10^9.Simple seive will give u tle.

»
6 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

I checked these https://ntheory.org/sieves/benchmarks.html but even the fastest library (till 10^9) ie Kim Walisch's was not as fast as min_25's sieve. I checked zimpha's wheelsieve as well. It is quite fast as well but slightly slower than min_25. Many of the above libraies are cache efficient and thread efficient code. Which neither min_25's nor zimpha's single file code is this shows we have lot more headrooms to improve.