0

I want optimize the sieve more further. I already have learnt wheel factorization from http://en.wikipedia.org/wiki/Wheel_factorization#Procedure. But i don't understand how can I implement wheel factorization in the sieve ?

bool status[N]={0};
void SOE(){
    status[0]=1;
    status[1]=1;
    status[2]=0;
    for(int i=4;i<N;i=i+2){
        status[i]=1;
    }
    int sqrtN=sqrt(N);;
    for(int i=3;i<=sqrtN;i=i+2){
        if(status[i]==0){
            for(int j=i*i;j<N;j+=i+i){
                status[j]=1;
            }
        }
    }
}
Will Ness
  • 70,110
  • 9
  • 98
  • 181
Maruf
  • 792
  • 12
  • 36
  • You might want to look at the Sieve of Atkin. – Jerry Coffin Aug 04 '13 at 06:42
  • In the algorithm description here, http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes, wouldn't it just mean replacing step 1 with the list generated from wheel factorization? – גלעד ברקן Aug 04 '13 at 08:51
  • I discuss Paul Pritchard's wheel sieve at [my blog](http://programmingpraxis.com/2012/01/06/pritchards-wheel-sieve/); it's too big to show here. Be aware that, though the asymptotic complexity of finding primes improves, constant factors mean that a simple Sieve of Eratosthenes beats Pritchard's wheel sieve every time. – user448810 Aug 04 '13 at 12:13

0 Answers0