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 O(log(n)) solution, does anyone know how to do it? It can be done recursively.
Well, you know that xa+b = xa xb so…