O(log(n)) power algorithm