Express as sum of power of natural numbers
Submissions: 1236   Accuracy:

46.8%

  Difficulty: Medium   Marks: 4

Given two numbers X and N, find out the total number of ways X can be expressed as sum of Nth power of unique natural numbers.

 

Examples:

Input  : X = 10, N = 2
Output : 1
Explanation: 10 = 12 + 32, 
Hence total 1 possibility

Input  : X = 100, N = 2
Output : 3
Explanation: 100 = 102
             OR 62 + 82
             OR 12 + 32 + 42 + 52 + 72
Hence total 3 possibilities

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a single line containing two space seperated integers denoting the values of X and N respectively.

Output:
For each test case output a new line containing a single integer denoting the total number of ways X can be expressed as sum of Nth power of unique natural numbers.

Constraints:
1<=T<=100
1<=X<=103
1<=N<=5

Example:
Input:
2
10 2
100 2

Output:
1
3

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.