406973: GYM102644 A Random Mood
Description
This is a training contest on matrix exponentiation. See the tutorial along with hints and video solutions here.
Limak is always either happy or sad. His mood switches with probability $$$p$$$ every second. If Limak is happy right now, what is the probability that he's happy after $$$n$$$ seconds?
InputAn integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$) and a real value $$$p$$$ ($$$0 < p < 1$$$) with at most 9 digits after floating point.
OutputPrint one line with the answer. The absolute error allowed is $$$10^{-6}$$$.
ExamplesInput1 0.7Output
0.3000000000Input
2 0.1Output
0.8200000000Input
11 0.06Output
0.6225404294Note
In the first sample test, there's probability $$$0.7$$$ that Limak changes his mood from happy to sad. Otherwise (with probability $$$0.3$$$), he stays happy.
In the second sample test, the answer is $$$0.1 \cdot 0.1 + 0.9 \cdot 0.9 = 0.82$$$ because we want Limak either to switch his mood twice or not to change the mood at all.