HDU 2503 a/b + c/d

水题

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int T;
int a,b,c,d;

int gcd(int a,int b)
{
    int t;
    while(b)
    {
        t = a%b;
        a = b;
        b = t;
    }
    return a;
}

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int x=a*d+b*c;
        int y=b*d;
        int z=gcd(x,y);
        printf("%d %d\n",x/z,y/z);
    }
    return 0;
}

 

posted @ 2015-10-21 22:31  Fighting_Heart  阅读(115)  评论(0编辑  收藏  举报