cpp implementation of pow(x, n)