Nth root of a number

I am not able to derive the logic behind the problem .Please help

Hey @anishmittal
According to the question,
You are given two integers n and k. Find the greatest integer x, such that, x^k <= n.

For the test cases given:
2
10000 1
1000000000000000 10

In the first case, n = 10000 and k = 1, so the maximum integer x such that x^1 <= 10000 is 10000, coz if we take integers greater than 10000, then x^k will become > n, hence the greatest integer required is 10000.
In the second case, the greatest integer x such that x^10 is less than or equal to 1000000000000000 is 31 coz 32^10 is greater than 1000000000000000.

To solve this question, you can simply use linear search from 1 till n, coz the largest answer can be n itself, but the range of n is given as 10^15, so the linear search approach is going to give a TLE. Hence we use binary search,
Try writing the code and do ask if you face any problems.

i am facing a dilema of how to replace pow function because if i make my own power function using loop then complexity will shoot o(n3) ,if not power function won’t handle such big values

@anishmittal you can use the normal inbuilt pow function in C++ to solve this problem. the arguments going inside pow will be x and k, which will be in integer range, so it’s cool to use inbuilt pow function.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.