Brainstorm: To compute x/y in log(n) time, [closed]
How will you compute x/y in O(log(n)) time.
n=x/y, x & y are integers
You can't use the / operator.
One implementation is to add y q times till the result is less than x i.e.
y * q < x
What about 10**(log(x) - log(y))
Big O() notation only applies to how a problem scales with different number of inputs.
The question doesn't make sense unless you mean 'n' is the number of digits in x and y
精彩评论