I'm trying to solve this problem: http://www.codeforces.com/problemset/problem/7/D
And here is my solution: http://www.codeforces.com/contest/7/submission/2865747
My code might look little bit ugly, because I tried to optimize it as much as I can, it's linear solution but it's getting TLE. Why is the time limit so strict like this? Is there any optimizations I can make? I think my solution is the intended solution.
Edit: I got it accepted after pre-computing all the powers instead of using my power function.