#!/usr/bin/env python3 """job #1897 — route 75 triage: cost scaling of the REVISED-choices two-class cover. Route 75's own stated weakest assumption: "The revised-choices construction consumes 6210 primes up to 61871, so its cost grows with y in a way this run did not extrapolate." A full cover consumes ONE distinct prime per stage-1 twin-slot survivor (the injective variant), so the cost of the revised construction is governed by S(y, z) = #{ n in [1,y] : gcd(n(n+2), P(z)) = 1 }, P(z) = prod_{p<=z} p, and the largest prime an injection must reach is the (pi(z)+S)-th prime if the primes above z are consumed in increasing order. Both are pure sieving — no covering/matching is re-derived here. Controls (published, only used to validate the reader, not reported as new results): y=2e5, z=floor(sqrt(y)) -> 2137 survivors y=2e5, z=floor(sqrt(y)/log y) -> 6210 survivors, largest prime 61871 (injective row) Extensions (new): y = 2e6, 2e7 at both cutoffs. Deterministic stdout; no timings on stdout. """ import json import math PRIME_LIMIT = 40_000_000 # > 2e7 def primes_upto(n): sieve = bytearray([1]) * (n + 1) sieve[0:2] = b"\x00\x00" for i in range(2, int(n ** 0.5) + 1): if sieve[i]: sieve[i * i :: i] = bytearray(len(range(i * i, n + 1, i))) return [i for i in range(n + 1) if sieve[i]] PRIMES = primes_upto(PRIME_LIMIT) def pi(x): lo, hi = 0, len(PRIMES) while lo < hi: mid = (lo + hi) // 2 if PRIMES[mid] <= x: lo = mid + 1 else: hi = mid return lo def survivors(y, z): """Count n in [1,y] with gcd(n(n+2), P(z))=1 (none of n, n+2 divisible by a prime <= z).""" small = [p for p in PRIMES if p <= z] marked = bytearray(y + 3) for p in small: if p == 2: marked[0 : y + 1 : 2] = b"\x01" * len(range(0, y + 1, 2)) # n even else: marked[0 : y + 1 : p] = b"\x01" * len(range(0, y + 1, p)) # n = 0 mod p marked[p - 2 : y + 1 : p] = b"\x01" * len(range(p - 2, y + 1, p)) # n = -2 mod p return sum(1 for n in range(1, y + 1) if not marked[n]) def largest_prime_needed(y, z): """The (pi(z)+S)-th prime: how far an increasing-order injection must reach.""" s = survivors(y, z) idx = pi(z) + s # 1-based index into PRIMES return s, (PRIMES[idx - 1] if idx - 1 < len(PRIMES) else None) def main(): out = {"prime_limit": PRIME_LIMIT, "primes_available": len(PRIMES), "rows": []} for y in (200_000, 2_000_000, 20_000_000): ly = math.log(y) for label, z in (("sqrt(y)", math.floor(math.sqrt(y))), ("sqrt(y)/log y", math.floor(math.sqrt(y) / ly))): s, pneed = largest_prime_needed(y, z) out["rows"].append({ "y": y, "cutoff": label, "z": z, "pi_z": pi(z), "survivors": s, "largest_prime_if_increasing_injection": pneed, "survivors_over_y_times_ln2y": round(s / (y / ly ** 2), 6), "pneed_over_sqrt_y": (round(pneed / math.sqrt(y), 4) if pneed else None), "pneed_over_z": (round(pneed / z, 4) if pneed and z else None), }) print(json.dumps(out, indent=1, sort_keys=True)) if __name__ == "__main__": main()