// ============================================================================ // job #1007 — EVERY attaining position of the twin-Jacobsthal record A_1(x) // ============================================================================ // Object: A_1(x) = G2(x#), the largest gap between consecutive integers n with // gcd(n(n+2), x#) = 1 (OEIS A144311 + 1), over ONE period x#. // // The served enumerators (research/05-twin-jacobsthal.js, 05b) report the // maximum and ONE position. Route 10's next experiment needs the whole // attaining SET, because the record has multiplicity up to 20 and the end / // interior split may be witness noise rather than a property of the level. // // Method is the served one (05b's segmented stride marking), extended: // * each shard keeps the top-K gaps it sees inside its range, with their // starts, instead of only the running maximum; // * shards report their first and last slot so the combine step can add the // gaps that straddle a shard boundary and the cyclic wrap at the period end. // // Usage: node twin-jac-max.js [K] [segMillions] // Output: one JSON object on stdout. Progress goes to stderr. // ============================================================================ 'use strict'; const PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]; function main() { const x = Number(process.argv[2]); const shard = Number(process.argv[3]); const nShards = Number(process.argv[4]); const K = Number(process.argv[5] || 64); const SEG = Number(process.argv[6] || 100) * 1e6; const idx = PRIMES.indexOf(x); if (idx < 0) throw new Error('x must be a stacked prime, got ' + x); const PR = PRIMES.slice(0, idx + 1); let P = 1; for (const p of PR) P *= p; // x# <= 2.0e11 < 2^53 const lo = Math.floor(P * shard / nShards); const hi = (shard === nShards - 1) ? P : Math.floor(P * (shard + 1) / nShards); const buf = new Uint8Array(Math.min(SEG, hi - lo)); let top = []; // [[gap, start], ...], gap desc let count = 0, firstSlot = -1, prev = -1; function offer(gap, start) { if (gap <= 0) return; if (top.length === K && gap <= top[top.length - 1][0]) return; let i = top.length; while (i > 0 && top[i - 1][0] < gap) i--; if (i === top.length && top.length === K) return; top.splice(i, 0, [gap, start]); if (top.length > K) top.pop(); } const t0 = Date.now(); for (let base = lo; base < hi; base += buf.length) { const len = Math.min(buf.length, hi - base); buf.fill(0, 0, len); for (const p of PR) { const residues = (p === 2) ? [0] : [0, p - 2]; for (const res of residues) { let j = (res - (base % p)) % p; if (j < 0) j += p; for (; j < len; j += p) buf[j] = 1; } } for (let i = 0; i < len; i++) { if (buf[i] === 0) { const r = base + i; count++; if (firstSlot < 0) firstSlot = r; else offer(r - prev, prev); prev = r; } } if (process.stderr.write && (base / buf.length) % 8 === 0) { process.stderr.write(`... x=${x} shard ${shard}/${nShards} ${(100 * (base - lo) / (hi - lo)).toFixed(1)}% ` + `best=${top.length ? top[0][0] : 0} ${((Date.now() - t0) / 1000).toFixed(0)}s\n`); } } process.stdout.write(JSON.stringify({ x: x, P: P, shard: shard, nShards: nShards, K: K, lo: lo, hi: hi, slotCount: count, firstSlot: firstSlot, lastSlot: prev, top: top, seconds: (Date.now() - t0) / 1000 }) + '\n'); } main();