What case am I missing, unable to find it out.
I re-wrote x^k <= n as log(x) <= (log(n)) / k and then using BS to find out x
What case am I missing, unable to find it out.
I re-wrote x^k <= n as log(x) <= (log(n)) / k and then using BS to find out x
@Avi-Kasliwal-315786729062203 please share the complete code.
here base of log is e(around 2.71) so there may be many cases like x = 2, n=2, k=2 where it will return false.
@Avi-Kasliwal-315786729062203
log(x) <= (log(n)) / k , it is a floating point numbers comparision (i.e. doubles and float).
Floating point operations usually involve at least tiny rounding errors which are hard to predict. Therefore two floating point operations that should mathematically give the same result (like 4.7 * (1.0 / 3.14) vs. 4.7 / 3.14) may give different results.
for their comparsion use other way around:-
bool double_equals(double a, double b, double epsilon = 0.001)
{
return abs(a - b) < epsilon;
}
Hope it helps.
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.