Balls and Boxes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 797 Accepted Submission(s): 526
Problem Description
Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner that each ball has equal probability of going to each boxes. After the experiment, he calculated the statistical variance V as
where Xi is the number of balls in the ith box, and X¯ is the average number of balls in a box.
Your task is to find out the expected value of V.
V=∑mi=1(Xi−X¯)2m
where Xi is the number of balls in the ith box, and X¯ is the average number of balls in a box.
Your task is to find out the expected value of V.
Input
The input contains multiple test cases. Each case contains two integers n and m (1 <= n, m <= 1000 000 000) in a line.
The input is terminated by n = m = 0.
The input is terminated by n = m = 0.
Output
For each case, output the result as A/B in a line, where A/B should be an irreducible fraction. Let B=1 if the result is an integer.
Sample Input
2 1 2 2 0 0
Sample Output
0/1 1/2HintIn the second sample, there are four possible outcomes, two outcomes with V = 0 and two outcomes with V = 1.
Author
SYSU
Source
思路:一看到题目就觉着他肯定符合某个概率分布,然后就随便套了下二项分布的方差公式(D(x)=npq),竟然完全符合,就再想了下,发现确实是一个二项分布的题目
每个球都是独立的不相互影响的,进入每个篮子的概率是1/m。那么p=1/m,则D(x)=npq=n*(m-1)/m*m.
二项分布:二项分布即重复n次独立的伯努利试验。在每次试验中只有两种可能的结果,而且两种结果发生与否互相对立,并且相互独立,与其它各次试验结果无关,事件发生与否的概率在每一次独立试验中都保持不变。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
const int M=1e3+10;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
ll n,m;
int main()
{
while(~scanf("%lld%lld",&n,&m)){
if(n==0&&m==0)break;
ll ans=n*(m-1);
if(ans==0)printf("0/1\n");
else {
ll gcd=__gcd(ans,m*m);
printf("%lld/%lld\n",ans/gcd,(m*m)/gcd);
}
}
return 0;
}