The while loop is not iterating 4 times for n=10 and k=1.thereby printing 9.for big cases the error is coming .
Kth root .error in big cases and for n=10 and k=1 the output is coming out 9
@piyush.bansal8158625 We will use binary search approach to solve this problem.For every possible mid obtained by using binary search we will check if it is the best suitable candidate or not for becoming the Kth root and then we reduce the search space of the binary search according to the mid value. If mid^k is greater than N then we will find the best suitable value from left to mid-1 otherwise we will find much larger value by finding it from mid+1 to right.
But one important thing we need to do is to handle very large numbers that can be formed in computing mid^k.
So you should consider 3 cases:
First when k=1 : answer will simply be that number
when k=2: find the square root of that number , that would be the answer
for all other values of k:(do it by binary search)
Refer this code for help:
I had wriiten your code still not able to figure out the error in output
I have made the corrections, check it out.
got all wrong answers after submitting the code