Divide and Conquer: Exponentiation

Consider exponentiation, in which some number x is raised to some non-negative integer power n. If x is 3 and n is 20, then xn is

      320
      = 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅
        3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3 ⋅ 3
    

There are 19 multiplications in all.

Multiplication is associative, so we can perform those multiplications in any order we please.

For debugging: Click here to validate.