// zone-trial.c -- job #5, Method B: no sieve. Primes by trial division, holes by // testing r mod q for every prime q <= p (the definition: coprime to p#). // For every prime p <= PB prints, for the note's zone Z (r > p, r+2 < p'^2) and the // closed ceiling Z<= (r > p, r+2 <= p'^2): slot count, twin-prime count, bad slots. // Lines are formatted to be compared with the Z and Z<= columns of zone-conv.log. // Build: cc -O2 -o zone-trial zone-trial.c Run: ./zone-trial > zone-trial.log #include #include #define PB 2000u static int prime_td(uint64_t x) { if (x < 2) return 0; if (x % 2 == 0) return x == 2; for (uint64_t d = 3; d * d <= x; d += 2) if (x % d == 0) return 0; return 1; } static uint32_t qs[400]; static int nq; static int hole_td(uint64_t x, uint32_t p) { // gcd(x, p#) == 1 for (int i = 0; i < nq && qs[i] <= p; i++) if (x % qs[i] == 0) return 0; return 1; } int main(void) { for (uint32_t i = 2; i <= PB + 100 && nq < 400; i++) if (prime_td(i)) qs[nq++] = i; printf("# p p' | Z cand act bad | Z<= cand act bad | slot at r = p'^2-2\n"); for (int k = 0; k + 1 < nq && qs[k] <= PB; k++) { uint32_t p = qs[k], pn = qs[k + 1]; uint64_t pn2 = (uint64_t)pn * pn; uint64_t zc = 0, za = 0, zb = 0; for (uint64_t r = p + 1; r + 2 < pn2; r++) { if (!hole_td(r, p) || !hole_td(r + 2, p)) continue; zc++; if (prime_td(r) && prime_td(r + 2)) za++; else zb++; } uint64_t e = pn2 - 2; // the one extra r admitted by r+2 <= p'^2 int eslot = e > p && hole_td(e, p) && hole_td(e + 2, p); int etwin = prime_td(e) && prime_td(e + 2); printf("%u %u | %llu %llu %llu | %llu %llu %llu | %s\n", p, pn, (unsigned long long)zc, (unsigned long long)za, (unsigned long long)zb, (unsigned long long)(zc + eslot), (unsigned long long)(za + (eslot && etwin)), (unsigned long long)(zb + (eslot && !etwin)), eslot ? "yes" : "no"); } return 0; }