Where i am making mistake?

Please go through the code and help me.

Hey @raj.verma5454 couple of mistakes in your code

  1. in the root function m would be equal to (s+e)/2, not (s+e)/2k
  2. if m and k are large enough it’ll even overflow unsigned long long int so make the function bool, and each time you multiply ans with m just check if it is greater than n if it is return false else continue.

bool multiply(long long int m, int k, int n){
long long int ans = 1;
while(k > 0){
ans = ans * m;
if(ans > n)
return false;
}
return true;
}

And adjust the root accordingly

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.

Where are u facing issue ???

Giving wrong output for last test case. https://ide.codingblocks.com/s/294822

Initialise a with 1 and then try.