#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX 15485863
#define LMT 1000000

unsigned flag[MAX>>6];

#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))

void sieve() {
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
}


int main(int argc, char *argv[])
{
  long starttime = clock();
  sieve();
  starttime = clock() - starttime;
  printf("Time: %2d ms. Size: %d", starttime, MAX>>6);
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to