#!/usr/bin/env node // Independent control for job2821/kstar-ladder.mjs: the SAME definition, a DIFFERENT traversal. // The ladder enumerates slots (slots[i] + t*P). This one walks every integer r in [0, N) in order, // decides on the fly whether r is a slot and whether it is killed, and tracks the longest run of // consecutive slots. No index arithmetic, no lift decomposition, no tables: if the two agree, the // lift/lexicographic argument in the ladder is not what produced the value. // // node verify-independent.mjs 5-13 function gcd(a, b) { while (b) { const t = a % b; a = b; b = t; } return a; } function primesUpTo(n) { const o = []; for (let m = 2; m <= n; m++) { let p = true; for (const d of o) { if (d * d > m) break; if (m % d === 0) { p = false; break; } } if (p) o.push(m); } return o; } const prod = (a) => a.reduce((x, y) => x * y, 1); function kstarInteger(s) { const P = prod(primesUpTo(s)); const Q = primesUpTo(2 * s).filter((q) => q > s); const N = P * prod(Q); let run = 0, max = 0, prefix = 0, suffix = 0, seenUncovered = false; for (let r = 0; r < N; r++) { const isSlot = gcd(r, P) === 1 && gcd(r + 2, P) === 1; if (!isSlot) continue; let killed = false; for (const q of Q) { if (r % q === 0 || (r + 2) % q === 0) { killed = true; break; } } if (killed) { run++; if (run > max) max = run; if (r < P * prod(Q) && run === max && !seenUncovered) prefix = run; } else { run = 0; seenUncovered = true; if (prefix === 0) prefix = 0; } } // trailing ones of the period for (let r = N - 1; r >= 0; r--) { const isSlot = gcd(r, P) === 1 && gcd(r + 2, P) === 1; if (!isSlot) continue; let killed = false; for (const q of Q) { if (r % q === 0 || (r + 2) % q === 0) { killed = true; break; } } if (killed) suffix++; else break; } // leading ones for (let r = 0; r < N; r++) { const isSlot = gcd(r, P) === 1 && gcd(r + 2, P) === 1; if (!isSlot) continue; let killed = false; for (const q of Q) { if (r % q === 0 || (r + 2) % q === 0) { killed = true; break; } } if (killed) prefix++; else break; } return { s, P, Q, N, K: Math.max(max, prefix + suffix) }; } const spec = process.argv[2] || "5-13"; const m = /^(\d+)-(\d+)$/.exec(spec); const a = +m[1], b = +m[2]; for (let s = a; s <= b; s++) { const t0 = Date.now(); const r = kstarInteger(s); console.log("s=" + String(s).padEnd(3), "P=" + String(r.P).padEnd(9), "integers=" + r.N.toExponential(2).padEnd(9), "K*=" + r.K, ((Date.now() - t0) / 1000).toFixed(1) + "s"); }