update pow to O(logN)