Ways to Express an Integer as Sum of Powers - Problem
Given two positive integers n and x.
Return the number of ways n can be expressed as the sum of the xth power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1^x + n2^x + ... + nk^x.
Since the result can be very large, return it modulo 10^9 + 7.
Example: If n = 160 and x = 3, one way to express n is n = 2^3 + 3^3 + 5^3.
Input & Output
Example 1 — Basic Case
$
Input:
n = 10, x = 2
›
Output:
1
💡 Note:
Only one way: 10 = 1² + 3² = 1 + 9. We use unique positive integers 1 and 3.
Example 2 — Multiple Ways
$
Input:
n = 4, x = 1
›
Output:
5
💡 Note:
Two ways to express 4 as sum of unique positive integers to power 1: {4} gives 4¹=4, and {1,3} gives 1¹+3¹=1+3=4.
Example 3 — Larger Input
$
Input:
n = 160, x = 3
›
Output:
1
💡 Note:
One way to express 160 as sum of unique cubes: 2³ + 3³ + 5³ = 8 + 27 + 125 = 160.
Constraints
- 1 ≤ n ≤ 300
- 1 ≤ x ≤ 5
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code