Skip to content

Practice Ways to Express an Integer as Sum of Powers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2787
LeetCode Problem

Ways to Express an Integer as Sum of Powers

Problem Statement

Count sets of distinct positive integers whose xth powers add to n. Order does not distinguish sets, and no integer can be reused. Return the count modulo 10^9 + 7. For example, n = 160 and x = 3 permit 2^3 + 3^3 + 5^3.

Source: Ways to Express an Integer as Sum of Powers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 10, x = 2
Output
1

# Example 2

Input
n = 4, x = 1
Output
2

Constraints

1 <= n <= 300
1 <= x <= 5

Related LeetCode Problems

Practice more problems similar to Ways to Express an Integer as Sum of Powers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.