#include #include #include #define TEST(f,x) (*(f+(x)/16)&(1<<(((x)%16L)/2))) #define SET(f,x) *(f+(x)/16)|=1<<(((x)%16L)/2) int main(int argc, char *argv[]) { unsigned char *ptr=NULL; unsigned long max, mom, s=0, e=1; register unsigned long test=1; register unsigned long count=1; time_t begin; max = ( argc>1 ) ? atol(argv[1]) : 0xFFFFFFL; ptr = (unsigned char *) calloc( ((max>>4)+1L), sizeof(char) ); if ( ! ptr ) { printf( "Can't allocate enough memory!\n" ); system("pause"); return 1; } printf( "Searching prime numbers to : %ld\n", max ); begin = time (NULL); while ( (test+=2) < max) if (!TEST(ptr, test) ) { if ( ++count%0xFFL==0 ) { printf ( "%ld prime number\x0d", count ); fflush(stdout); } for ( mom=3L*test; mom