#!/usr/bin/env python3 """nmax_check.py -- job #4128 (route 2): independent max/min support counts N(a,L) at 19#. A[r] = 1 iff gcd(r, W) = 1 (sieve over the primes dividing W); the twin-admissible positions are twin[r] = A[r] & A[(r+2) % W]. With the prefix sums of twin over two periods, N(a,L) = C[a+L] - C[a] for the whole start range at once. This is separate from fastscan.c/fprofile.c (no shared code) and settles whether the served scanner's MAX_N = 84 cap is reached at the scanned lengths. """ import json import os import sys import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) W = 9699690 Q = (23, 29, 31, 37) def main(): A = np.ones(W, dtype=np.int32) for p in (2, 3, 5, 7, 11, 13, 17, 19): A[::p] = 0 twin = A & np.roll(A, -2) # twin[r] = A[r] & A[(r+2) % W] C = np.concatenate(([0], np.cumsum(np.tile(twin, 2), dtype=np.int64))) out = {"W": W, "q": list(Q), "twin_slots": int(twin.sum()), "density": float(twin.sum()) / W, "rows": []} for L in (593, 594, 650, 900, 1705, 2000, 2233, 2267): N = C[L:L + W] - C[0:W] # N(a, L) vectorised over a out["rows"].append({"L": L, "min_N": int(N.min()), "max_N": int(N.max()), "N_at_a0": int(N[0]), "N_at_a4186": int(N[4186]), "starts_over_MAX_N_84": int((N > 84).sum())}) # first L at which the served scanner's MAX_N = 84 would overflow for some start first = None lo, hi = 1, 4000 while lo < hi: mid = (lo + hi) // 2 N = C[mid:mid + W] - C[0:W] if N.max() > 84: hi = mid else: lo = mid + 1 first = lo out["first_L_with_some_N_gt_84"] = first N = C[first:first + W] - C[0:W] out["first_overflow_start"] = int(np.argmax(N)) out["first_overflow_N"] = int(N.max()) with open(os.path.join(HERE, "nmax_w19.json"), "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) print(json.dumps(out, indent=1)) return 0 if __name__ == "__main__": sys.exit(main())