您的位置:首页 > 其它

marshmallow (博弈论)

2016-02-27 19:36 387 查看
Description

Jack’s girlfriend loves marshmallow very much, so he buys her two bags of marshmallow on the Children’s Day. One of them is made up of red one’s, whose number is about n, and the other is blue with number of m. Suddenly Jack comes up with an idea that he can
play a game with his girlfriend and test her IQ as well. So he takes some marshmallow out from the red one’s, together from the blue one’s, and puts them on the table. Now it begins with his girlfriend, she picks up the marshmallow on the table and eats them,
then it’s Jack’s turn, after Jack, his girlfriend chooses, then Jack…… it goes on like this, but they have to follow some disciplines. Every time, he or his girlfriend can take away 1.any number of red one’s 2.any number of blue one’s 3.a red one, together
with a blue one, is a must and he or she can be the winner if he or she takes away the last one. Jack considers that he is the second to none smartest guy in the world, what surprises him is that his girlfriend is also very smart, which makes Jack feel embarrassed……
Assuming that there are red marshmallow and blue marshmallow on the table, whose numbers are i(1 <= i< =n) and j(1 <= j <= m) , and such situation’s probability is 1/(n * m). Jack wants to know how much probability he has to win the game.

Input

Group data, and each group is made up of two positive integer n and m (1 <= n, m <= 10000)

Output

Output Jack’s probability of winning the game with irreducible fraction, if he has no chance to win, please output 0/1

Sample Input

1 1
2 3
3 3
4 4


Sample Output

0/1
1/3
1/3
3/16


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 100000 + 10;
int main()
{
int n,m,a,b;
while(cin>>n>>m) {
if(n==1 && m==1) cout<<"0/1"<<endl;
else {
a=min(n,m);
b=n*m;
if(n==m && (n-1)%3==0) a--;
cout<<a/__gcd(a,b)<<"/"<<b/__gcd(a,b)<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: