Snail Alice is a snail indulged in math. One day, when she was walking on the grass, suddenly an accident happened. Snail Alice fell into a bottomless hole, which was deep enough that she kept falling for a very long time. In the end, she caught the lateral wall of the hole and stop falling down. She named the place where she stopped “lucky place” immediately.
Snail Alice decided to climb up along the wall from the “lucky place”. The first day she climbed up q0 (q is a positive constant integer) metres, but at night when she fell asleep, she fell down q1 metres. She was shocked when she woke up, and she decided to make an extra effort. The second day she finally climbed up q2 metres. To her surprise, she fell down faster because of the tiredness. She fell down q3 metres at night. The longer she climbed up the longer she fell down. But finally, she still climbed out of the hole and slept on the ground.
Lying on the grass safe, she was curious about a question. How many metres was the “lucky place” down under the ground? She remembered that the sum of the times of her climbing up and falling down is n(of course, n is odd), so the distance between the ground and the “lucky place” must be 1-q+q
2-q
3+...+(-1)
n-1q
n-1. Snail Alice simplified that long formula and get a beautiful result: (q
n+1)/(q+1). But as a math professor, she wouldn’t stop. She came up with a good problem to test her students. Here is the problem:
A function f(n), n is a positive integer, and
__poj_jax_start__f(n)=\left\{\begin{array}{cl}\frac{q^n+1}{q+1} & n\ is\ odd\\ \frac{q^n-1}{q+1} & n\ is\ even\end{array}\right.__poj_jax_end__
Given q and n, please calculate the value of f(n).Please note that q and n could be huge.