题目(http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=3)
对于两个最简的分数 a / b, c / d
把他们两个的最小公倍数 x / y 也设为一个分数形式,
那么这个 x 一定能够整除 a , c, y 一定能够被 b , d整除。
那么要求得最小公倍数,那么肯定是分子尽量小,即 a , c 的最小公倍数,
分母尽量大, 即 b , d 的最大公约数。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
return a/gcd(a,b)*b;
}
int main()
{LL a,b,c,d;
LL tmp;
int t;
cin>>t;
while(t--)
{
scanf("%lld/%lld",&a,&b);
scanf("%lld/%lld",&c,&d);
tmp=gcd(a,b);
a/=tmp,b/=tmp;
tmp=gcd(c,d);
c/=tmp,d/=tmp;
LL x,y;
x=lcm(a,c);
y=gcd(b,d);
if(y==1)
cout<<x<<endl;
else
cout<<x<<"/"<<y<<endl;
}
return 0;
}