思路

化简就是求一个gcd。

代码

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define int long long
using namespace std;
const int N=2e5+7;
const int mod=1e9+7;

//int read(){	int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=f*-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}

int t,a,b,c,d;

signed main(){
	cin>>t;
	while(t--){
		cin>>a>>b>>c>>d;
		int fm=b*d,fz=a*d+c*b,g=gcd(fm,fz);
		fm/=g;fz/=g;
		cout<<fz<<" "<<fm<<"\n"; 
	}
	return 0;
}