while solving this question I am getting tle again and again can some suggest me some efficient approach
Kth root problem
Hello @Divya_321,
Always share your code with your doubts as it helps in finding the actual fault in your code.
Now, coming back to your problem:
The constraint on N is:
1<=N<=10^15
Iterating it to N/2 i.e. 10^15/2=5*10^14.
It will cause TLE.
Solution:
You can implement a binary search to solve this question in log(n) time complexity.
You can refer to the following code:
Hope, this would help.
Give a like if you are satisfied.
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.
CODE lINK : https://pastebin.com/ZbyP3sRb
yep I am satisfied by your explanation , here’s my code and I am unable to figure out why it’s giving wrong ans as I have also applied same concept but inspite of using pow I have used binary exponentiation.
@S18ML0016
Hello @Divya_321,
To understand the difference, run the following two codes and compare the outputs for test case:
1
1000000000000000 10
Your Code:
My Code:
Hope, this would help in identifying the error.