CZ_PROB3 - Ping Pong Probability

Two Ping Pong players agree to play several games. The players are evenly matched. However, the person serving first has a probability p of winning that game. A serves the first game and thereafter the loser serves first. What is the Probability that A wins the nth game?

Input

Number of test cases T followed by T lines of 'n' - the number of games played; and 'p' probability of person serving first winning.
0 < T < 100

Output

Print for each test case the probability of A winning.
Please print a double value.

Example

Input:
2
4 0.7
7 0.7

Output:
0.4872
0.500819


Added by:Rahul
Date:2007-03-10
Time limit:0.100s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO
Resource:Dilip Rajeev

hide comments
2019-11-04 19:31:08
n <= 100. Input is badly formatted, use C-style "next number" reading in Python or other languages with line-based I/O.

Didn't know how this should be properly calculated so I've spent an enjoyable hour hacking around, figuring out patterns based on bruteforce and models and got AC with a solution I had thought would not be precise enough. If my approach was the expected one and there is no easy formula here, this surely should be a classical problem.

Last edit: 2019-11-04 20:18:08
2016-01-02 13:07:06
I too ave same doubt!
2011-04-08 12:27:33 Siarhei Khamenka
Is there any constraint on n ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.