Kth root problem


this code is working fine .there is no any issue .

but when i have made a trivial changes , at line 10 , in above code . here is the edited code

its giving the wrong answer

please explain why it is happening

Please check, both the codes are giving wrong answer.

correct answer code


this is giving wrong answer

Your working code should also have given the wrong answer, because calculating pow(mid,k) should gives wrong answer due to overflow. I would suggest you to write your own power function to handle overflow.

1 Like

but it has passed all the test cases

There has to be some issue with compiler.
You are calculating pow(n,k) in which n can be (10^15)/2 and k can be 10000. Now that is a very large number which cannot be stored in long long , so your code is working somehow because of some garbage value. I can assure you its incorrect and suggest you to write your own power function which checks the overflow rather than relying on 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.