Mathematical Example

Find an algorithm for raising a number X to the power N, where N is a positive integer, using only multiplication and subtraction. The problems we can solve directly are:

For N > 2, we split the original problem into two subproblems:

If I=1 or I=2 we can solve P1 directly, otherwise we solve it recursively as described. If N-I=1 or N-I=2 we can solve P2 directly, otherwise we solve it recursively too.