Best way to do powerOf(int x, int n)?
- by Mike
So given x, and power, n, solve for X^n.
There's the easy way that's O(n)...
I can get it down to O(n/2), by doing
numSquares = n/2;
numOnes = n%2;
return (numSquares * x * x + numOnes * x);
Now there's a log(n) solution, does anyone know how to do it? It can be done recursively.