2787. Ways to Express an Integer as Sum of Powers Medium

@problem@discussion
#Dynamic Programming



1/**
2 * [2787] Ways to Express an Integer as Sum of Powers
3 *
4 * Given two positive integers n and x.
5 * Return the number of ways n can be expressed as the sum of the x^th 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.
6 * Since the result can be very large, return it modulo 10^9 + 7.
7 * For example, if n = 160 and x = 3, one way to express n is n = 2^3 + 3^3 + 5^3.
8 *  
9 * <strong class="example">Example 1:
10 * 
11 * Input: n = 10, x = 2
12 * Output: 1
13 * Explanation: We can express n as the following: n = 3^2 + 1^2 = 10.
14 * It can be shown that it is the only way to express 10 as the sum of the 2^nd power of unique integers.
15 * 
16 * <strong class="example">Example 2:
17 * 
18 * Input: n = 4, x = 1
19 * Output: 2
20 * Explanation: We can express n in the following ways:
21 * - n = 4^1 = 4.
22 * - n = 3^1 + 1^1 = 4.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= n <= 300
28 * 	1 <= x <= 5
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/ways-to-express-an-integer-as-sum-of-powers/
34// discuss: https://leetcode.com/problems/ways-to-express-an-integer-as-sum-of-powers/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn number_of_ways(n: i32, x: i32) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_2787() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.