406973: GYM102644 A Random Mood

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Random Moodtime limit per test0.25 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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?

Input

An integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$) and a real value $$$p$$$ ($$$0 < p < 1$$$) with at most 9 digits after floating point.

Output

Print one line with the answer. The absolute error allowed is $$$10^{-6}$$$.

ExamplesInput
1 0.7
Output
0.3000000000
Input
2 0.1
Output
0.8200000000
Input
11 0.06
Output
0.6225404294
Note

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.

加入题单

上一题 下一题 算法标签: