Can't seem to make my code works for larger inputs

You are using un necessary for loop, a simple binary search will work.

1 Like

In your for loop, you are calculating power till k, that will lead to over flow, keep a check condition that will break the loop.
or you can use a pow function(custom pow function)
or you can use inbuilt pow function to solve the problem in one line
long long ans=pow(N,(long double)(1)/K);
If this solves your doubt mark it as resolved.

1 Like