Drinks
Time limit2sMemory limit256 MB
Two players alternately draw balls without replacement until the first red ball appears, and you compute the chance the first player draws it.
- Level
Medium4 of 10
- Topics
- Probability, Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
Every weekend dreamoon and drazil play in the park. Each time they meet, one of them has to buy drinks for both, and they settle who pays with this procedure.
- Put red balls and white balls into a paper bag.
- dreamoon and drazil take turns drawing one ball from the bag. A drawn ball is not put back.
- Whoever draws a red ball first buys the drinks.
drazil lets dreamoon draw first every week because dreamoon is older. One day dreamoon started wondering how likely he is to draw a red ball first. Every ball still in the bag is equally likely to be drawn. Compute that probability.
Input
The first line contains the number of test cases , where .
Each of the next lines contains the number of red balls and the number of white balls , separated by a space. The values satisfy , , and .
Output
For each test case, print on one line the probability that dreamoon draws a red ball first, written as a reduced fraction . Here and are coprime positive integers, and there is no space around the slash.