Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursive with decreasing upperbounds solution in Clear category for Sum of Distinct Cubes by Phil15
from math import cbrt
def sum_of_cubes(n: int, upperbound: int = float('inf')) -> list[int] | None:
if n == 0:
return []
if n == 1:
return [1]
n3 = min(int(cbrt(n)), upperbound)
for k in range(n3, 0, -1):
if (res := sum_of_cubes(n - k ** 3, k - 1)) is not None:
return [k] + res
return None
July 31, 2023
Comments: