

‘N’ = 30 and ‘K’ = 2
So, the number of ways is 2.
First, 1^2 + 2^2 + 3^2 + 4^2
Second, 1^2 + 2^2 + 5^2
You cannot use any number two or more times in expressing a number ‘N’. For example, 8 cannot be broken as 2^2 + 2^2.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain two space-separated integers ‘N’ and ‘K’ where ‘N’ is the number that Kevin wants to break, and ‘K’ is the number that represents the power to which natural numbers must be raised.
For each test case, print the number of ways Kevin can perform his task described above.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 10
1 <= N <= 10^5
1 <= K <= 20
Time limit: 1 sec
The basic idea is to go recursively and check whether a particular natural number be part of anyway (in which ‘N’ can be broken).
We are going to use an additional function as:
int helper( int n, int k, int num)Where ‘n’ is the number that Kevin wants to break, ‘k’ is the required power, and ‘num’ is a number that can be a part of broken ‘n’.
There will be two recursive calls at each step, one in which ‘num’ is taken as a part of broken ‘n’ and another in which it is not be taken.
The basic idea of this approach is to first solve the subproblems then reach the main solution and this is done by applying the bottom-up approach of DP.