#include #include int main() { int limit = 250000000; int cur, i, j, sqrt_limit; //allocate the array char *primes = (char *)malloc(limit+1); primes[0]='f'; primes[1]='f'; //initialize our sieve for (i=2;i<=limit;i++) primes[i]='t'; printf("List created\n"); //using the int allows int to int compares and is faster than float to int sqrt_limit=(int)sqrt(limit); //outer loop for how high we need to test sqrt(limit) as w/ simple prime testing //if ensues we only do inner loop if i is a prime //inner loop crosses off the multiples for (i=2;i<=sqrt_limit;i++) if (primes[i]=='t') for (j=i*2;j<=limit;j+=i) primes[j]='f'; /* for (i=2;i<=limit;i++) if (primes[i]=='t') printf("%d ",i); */ free (primes); return 1; }