What is the fastest way to calculate x given y as a large integer?
$y = 100$
$z = 2$
$x = 64$ (Power of z and smaller than or equal to y).
$x = f(100, 2) = 64$
$x = f(128, 2) = 128$
$x = f(90, 3) = 81$
What is the fastest way to calculate x given y as a large integer?
$y = 100$
$z = 2$
$x = 64$ (Power of z and smaller than or equal to y).
$x = f(100, 2) = 64$
$x = f(128, 2) = 128$
$x = f(90, 3) = 81$
If you want to avoid a loop you may use : $\displaystyle x=z^{\lfloor\frac{\ln(y)}{\ln(z)}\rfloor}$
else multiply $1$ by $z$ until being greater than $y$ and return the previous value.
$\huge x= z^{\lfloor (\log_z y) \rfloor}$
What this means is you take the largest integer which is less than the logarithm base z of y. (this is the largest integer power you can raise z to get a number smaller than or equal to y) raise z to this power to get x.