Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4610 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 603 |

@akashverma4 | 363 |

@swastik8750 | 300 |

@nishunishuraj18 | 286 |

@surajmamgai | 264 |

@anks9013 | 222 |

@nayan2709 | 213 |

@burhanuddinbohra72 | 212 |

@realname | 203 |

@amank8975 | 203 |

@manmeetkaur18102000 | 202 |

Complete Leaderboard |

Given two numbers** n** and **x**, find out the total number of ways **n** can be expressed as sum of** x**th power of unique natural numbers.

**Example 1:**

Input: n = 10, x = 2Output:1Explanation: 10 = 1^{2}+ 3^{2}, Hence total 1 possibility.

**Example 2:**

Input:n = 100, x = 2Output:3Explanation: 100 = 10^{2}6^{2}+ 8^{2}and 1^{2}+ 3^{2}+ 4^{2}+ 5^{2}+ 7^{2}Hence total 3 possibilities.

**Your Task: **

You dont need to read input or print anything. Complete the function **numOfWays() **which takes n and x as input parameter and returns the total number of ways n can be expressed as sum of xth power of unique natural numbers.

**Expected Time Complexity:** O(n^{2}logn)

**Expected Auxiliary Space:** O(n)

**Constraints:**

1 <= n <= 10^{3}

1 <= x <= 5

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Express as sum of power of natural numbers

...