Class Solution
- java.lang.Object
-
- g2701_2800.s2787_ways_to_express_an_integer_as_sum_of_powers.Solution
-
public class Solution extends Object
2787 - Ways to Express an Integer as Sum of Powers.Medium
Given two positive integers
nandx.Return the number of ways
ncan be expressed as the sum of thexthpower of unique positive integers, in other words, the number of sets of unique integers[n1, n2, …, nk]wheren = n1x + n2x + … + nkx.Since the result can be very large, return it modulo
109 + 7.For example, if
n = 160andx = 3, one way to expressnisn = 23 + 33 + 53.Example 1:
Input: n = 10, x = 2
Output: 1
Explanation:
We can express n as the following: n = 32 + 12 = 10.
It can be shown that it is the only way to express 10 as the sum of the 2nd power of unique integers.
Example 2:
Input: n = 4, x = 1
Output: 2
Explanation:
We can express n in the following ways:
-
n = 41 = 4.
-
n = 31 + 11 = 4.
Constraints:
1 <= n <= 3001 <= x <= 5
-
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intnumberOfWays(int n, int x)
-