Please go through the code and help me.
Where i am making mistake?
Hey @raj.verma5454 couple of mistakes in your code
- in the root function m would be equal to (s+e)/2, not (s+e)/2k
- 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 ???
Initialise a with 1 and then try.