#includeusing namespace std;int gcd ( int a, int b){ return b ? gcd ( b, a % b ) : a ;}int main(){ int t; scanf("%d",&t); while(t--) { int op,a,b,c,d; scanf("%d %d %d %d %d",&op,&a,&b,&c,&d); if(op==1) { int x,y,sum; x=b*d/gcd(b,d); sum=x/b*a+x/d*c; y=gcd(x,sum); printf("%d/%d\n",sum/y,x/y); } else { int x,y,sum; x=b*d/gcd(b,d); sum=x/b*a-x/d*c; if(sum<0) y=gcd(x,-sum); else y=gcd(x,sum); printf("%d/%d\n",sum/y,x/y); } } return 0;}
题目链接: