21 2 1 34 3 2 3 Sample Output5 62 1
#include<stdio.h>#include<algorithm>#include<iostream>using namespace std;int gcd(int n,int m){ int t,r; if(m>n) { t=n;n=m;m=t; } while(m) { r=n%m; n=m; m=r; } return n;}int main(){ int t; scanf("%d",&t); while(t--) { int a,b,c,d,m,n; int k; scanf("%d%d%d%d",&a,&b,&c,&d); n=a*d+c*b; m=b*d; if(n==m) printf("1/n"); else k=gcd(n,m); printf("%d %d/n",n/k,m/k); }}
新闻热点
疑难解答