Submit | All submissions | Best solutions | Back to list |
CANDY4 - Candy IV |
Lazy Child is a lazy child who likes candy very much. Despite being very young, he has two large candy boxes, each initially containing n candies. Everyday he picks one box and open it, if there still are candies, he would eat one. If not, he would be quite sad and open the other box. He will pick the first box with probability p and the second box with probability 1-p. He might cry if the other box contains few candies.
He opens a box and finds it's not empty, then takes out 1 candy from it and eats it for several days, while he can't remember how many days are there exactly. One day, he opens a box, only to find no candy left. Before opening the other box, he wants to know the expected number of candies left in the other box. Can you help him?
Input
There are several test cases (about 100), please process till EOF.
Each of the following lines contains an integer n (1 ≤ n ≤ 20000) and a real number p (0 ≤ p ≤ 1, with 6 digits after the decimal).
Output
Please print one line per case containing the desired answer. Any answer with an absolute error less than or equal to 10-2 would be accepted. Please see the sample output for detailed format.
Example
Input: 10 0.400000 100 0.500000 124 0.432650 325 0.325100 532 0.487520 2276 0.720000 Output: Case 1: 3.528175 Case 2: 10.326044 Case 3: 28.861945 Case 4: 167.965476 Case 5: 32.601816 Case 6: 1390.500000
Added by: | Fudan University Problem Setters |
Date: | 2008-08-01 |
Time limit: | 2s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: C99 ERL JS-RHINO NODEJS PERL6 |
Resource: | ACM/ICPC Regional Contest, Chengdu 2012 |