You are viewing a single comment's thread. Return to all comments →
Python3 code using dynamic programming approach, similar to coin change problem, time complexity O(x^(1 + 1 / n)).
x = int(input()) n = int(input()) dp = [1] + [0] * x for i in range(1, int(pow(x, 1 / n)) + 1): u = i ** n for j in range(x, u - 1, -1): dp[j] += dp[j - u] print(dp[-1])
Seems like cookies are disabled on this browser, please enable them to open this website
The Power Sum
You are viewing a single comment's thread. Return to all comments →
Python3 code using dynamic programming approach, similar to coin change problem, time complexity O(x^(1 + 1 / n)).