mth power algorithm

A complete description of the algorithm can be found here.

Input: m = n =