0
$\begingroup$

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$

  • 0
    @ThomasAndrews Thanks! Now the question is clear :-)2012-07-25

2 Answers 2

1

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.

  • 0
    $\lfloor w \rfloor$ is the largest integer smaller than or equal to $w$2012-07-25
1

$\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.