HDU5810 Balls and Boxes(Boxes and Balls)
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Description |
Title Description |
Mr. Chopsticks is interested in the random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner so each ball have equal probability of going to each B Oxes. After the experiment, he calculated the statistical variance V Aswhere are the number of balls in the ith box, and is the Average number of balls in a box. Your task is to find out the expected value of V. |
Mr. Chopsticks a sudden interest in random phenomena, and did an experiment to study randomness. In the experiment, he throws the probability of n balls into M-boxes. Then he calculates the variance with the following equation V Indicates the number of balls in the box I, indicating the average of the balls in each box. Your job is to find out what V expects. |
Input |
Input |
The input contains multiple test cases. Each case contains the integers n and m (1 <= N, M <=) in a line. The input is terminated by n = m = 0. |
Multiple sets of test cases. Each test case has a row of two integers n and m (1 <= N, m <= 1000 000 000). n = m = 0 o'clock, the input ends. |
< P align= "Center" >output |
output |
for Each case, output the result as A/b in A line, where A/b should is an irreducible fraction. Let b=1 if the result was an integer. &NBSP; |
for each use case, The output row result is a/b,a/b to an irreducible fraction. When the result is an integer, make the b=1. &NBSP; |
Sample Input-Enter sample |
Sample output-export example |
2 1 2 2 0 0 |
0/1 1/2 |
Hint |
Tips |
In the second sample, there is four possible outcomes, and the other outcomes with V = 0 and both outcomes with V = 1. |
In the second example, there are 4 possible results, two V = 0, and one v = 1. |
Exercises
Similar to the two-item distribution of the experiment, get all the possible variance, then the other side to expect ... Wait, isn't that the variance of the two distributions? (Brain one pumping: all possible + take expectations = equal probabilities)
Two-item distribution D (X) = NP (1-P)
p = 1/m brought into D (X)
"Code C + +"
1#include <cstdio>2 __int64 GCD (__int64 A, __int64 b) {3 __int64 C;4 while(c = a%b) A = b, b =C;5 returnb;6 }7 intMain () {8 __int64 N, M, G;9 while(SCANF ("%i64d%i64d", &n, &m), n +m) {TenN *= M-1; M *=m; Oneg =GCD (n, m); Aprintf"%i64d/%i64d\n", n/g, M/g); - } - return 0; the}
HDU 5810 Balls and Boxes (box and Ball)