Use the right sieve algorithm.
@@ -9,9 +9,9 @@ int sieve (int n) {
for (iter = 0; iter < n; iter++) {
count = 0;
for (i = 0; i < SieveSize; i++) flags[i] = 1;
- for (i = 0; i < SieveSize; i++)
+ for (i = 1; i < SieveSize; i++)
if (flags[i]) {
- prime = i + i + 3;
+ prime = i + 1;
for (k = i + prime; k < SieveSize; k += prime) flags[k] = 0;
count++;
}
@@ -22,6 +22,6 @@ int main (void) {
int n = sieve (N_ITER);
printf ("%d iterations of sieve for %d: result = %d\n", N_ITER, SieveSize, n);
- if (n != 123814) abort ();
+ if (n != 65333) abort ();
return 0;
}
