Kth root (divide and conquer)

not getting output

@souravraj024
There are some mistakes in your code:-

  1. You are not calculating mid, inside the while loop, also calculate it in this way for avoiding overflow.
    mid = start + (end-start)/2;
  2. end variable should be initialized as n not n-1 as it can have this value.
  3. Also keep saving value in x variable even in the case of pow(mid,k)<n , because the condition is x^k <=n as given in question.
    Do these corrections then it will be fine

@souravraj024 do you get what I am saying??

yes , now the code is giving correct output . Thanks

1 Like