I have this method:
power (x, n) {
if n == 0
return 1
if n is even
return power(x * x, n/2)
if n is odd
return power(x * x, n/2) * x
I thought to calculate x ^ 64, which can be done using 6 multiplication actions, and then get x ^ 62 from there, but here I stuck. We can achieve it only by dividing by x and then again by x and not multiplying. Any idea of how to solve it or maybe another approach?
if n==0 return 1
, and I'd follow it withif n==1 return x
. – hardmath Mar 09 '19 at 18:25