Just RandomTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 213 Accepted Submission(s): 30
Problem Description ªêCoach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In each game the following will be done: ªê1. Coach Pang randomly choose a integer x in [a, b] with equal probability. ªê2. Uncle Yang randomly choose a integer y in [c, d] with equal probability. ªê3. If (x + y) mod p = m, they will go out and have a nice day together. ªê4. Otherwise, they will do homework that day. ªêFor given a, b, c, d, p and m, Coach Pang wants to know the probability that they will go out.
Input ªêThe first line of the input contains an integer T denoting the number of test cases. ªêFor each test case, there is one line containing six integers a, b, c, d, p and m(0 <= a <= b <= 109, 0 <=c <= d <= 109, 0 <= m < p <= 109).
Output ªêFor each test case output a single line "Case #x: y". x is the case number and y is a fraction with numerator and denominator separated by a slash ('/') as the probability that they will go out. The fraction should be presented in the simplest form (with the smallest denominator), but always with a denominator (even if it is the unit).
Sample Input 4
0 5 0 5 3 0
0 999999 0 999999 1000000 0
0 3 0 3 8 7
3 3 4 4 7 0
Sample Output Case #1: 1/3
Case #2: 1/1000000
Case #3: 0/1
Case #4: 1/1
Statistic | Submit | Clarifications | Back
|