Segmented Sieve of Eratosthenes?

后端 未结 5 528
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 13:15

It\'s easy enough to make a simple sieve:

for (int i=2; i<=N; i++){
    if (sieve[i]==0){
        cout << i << \" is prime\" << endl;
           


        
5条回答
  •  孤城傲影
    2020-11-22 13:52

    There's a version of the Sieve based on priority queues that yields as many primes as you request, rather than all of them up to an upper bound. It's discussed in the classic paper "The Genuine Sieve of Eratosthenes" and googling for "sieve of eratosthenes priority queue" turns up quite a few implementations in various programming languages.

提交回复
热议问题