Given two integers x and n, we need to find number of ways to express x as sum of n-th powers of unique natural numbers. It is given that 1 <= n <= 20.
Input : x = 100 n = 2 Output : 3 Explanation: There are three ways to express 100 as sum of natural numbers raised to power 2. 100 = 10^2 = 8^2+6^2 = 1^2+3^2+4^2+5^2+7^2 Input : x = 100 n = 3 Output : 1 Explanation : The only combination is, 1^3 + 2^3 + 3^3 + 4^3
We use recursion to solve the problem. We first check one by one that the number is included in summation or not.
This article is contributed by Anjali. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count number of ways to partition a set into k subsets
- Count number of ways to arrange first N numbers
- Count the number of ways to construct the target string
- Count number of ways to reach a given score in a Matrix
- Count the number of ways to divide N in k groups incrementally
- Count of ways to split a given number into prime segments
- Count ways to reach a score using 1 and 2 with no consecutive 2s
- Count of ways to traverse a Matrix according to given conditions
- Count ways to reach the Nth stair using any step from the given array
- Number of ways to divide a given number as a set of integers in decreasing order
- Count ways to change direction of edges such that graph becomes acyclic
- Count total ways to reach destination from source in an undirected Graph
- Number of ways to reach the end of matrix with non-zero AND value
- Number of ways to split N as sum of K numbers from the given range
- Number of ways to color N-K blocks using given operation
- Number of ways to choose elements from the array such that their average is K
- Number of ways to make binary string of length N such that 0s always occur together in groups of size K
- Number of ways in which an item returns back to its initial position in N swaps in array of size K
- Minimum tiles of sizes in powers of two to cover whole area
- Count number of pairs with the given Comparator