power O(logN) solution