import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int f = b/gcd(b, d)*d;
int e = a*(f/b)+c*(f/d);
int gcd = gcd(e, f);
f = f/gcd;
e = e/gcd;
System.out.println(e+" "+f);
}
sc.close();
}
public static int gcd(int x ,int y){
if (x<y) {
int temp = x;
x = y ;
y = temp;
}
//求最大公约数---辗转相除法(x>y)
while(y>0){
int num = x%y;
x = y;
y = num;
}
return x;
}
}
HDOJ 2503 a/b + c/d(求最大公约数)
最新推荐文章于 2021-04-06 19:58:15 发布