题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1417
假设 ans=n/m,C=(A+B)/2
若出正面 E_1 = nA-(m-n)C
若出反面 E_2 = (m-n)B-nC
由样例解释可知
得 m = A+B+2C,n=B+C
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL gcd(LL a,LL b) { return b? gcd(b,a%b):a; } int main() { LL T;cin>>T; while(T--) { LL a,b,c; cin>>a>>b; c=(a+b)/; LL m=a+b+*c,n=b+c; LL g=gcd(m,n); printf("%lld/%lld\n",n/g,m/g); } }