CCPC2016长春B (hdu 5912 Fraction)

water

 

 

 

//#define test
#include<bits/stdc++.h>
using namespace std;
const int Nmax=1e6+7;
typedef long long ll;
struct LL
{
    ll a,b;
    LL(){ }
    LL(ll aa,ll bb){ 
        a=aa,b=bb;
        ll g=__gcd(a,b);
        a/=g;
        b/=g;
    }
    friend LL operator + (const LL &a,const LL &b)
    {
        ll t2=a.b*b.b, t1=a.a*b.b+a.b*b.a;
        return LL(t1,t2);
    }
    friend LL operator + (const ll &a,const LL &b)
    {
        ll t1=a*b.b+b.a;
        return LL(t1,b.b);
    }
    friend LL operator / (const ll &a,const LL &b)
    {
        return LL(a*b.b,b.a);
    }


};
int n;
ll a[Nmax],b[Nmax];
int main()
{
    #ifdef test
    #endif
    int t;
    //freopen("b.in","r",stdin);
    scanf("%d",&t);
    for(int _=1;_<=t;_++)
    {
        LL ans(0,1);
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        for(int i=1;i<=n;i++)
            scanf("%lld",&b[i]);
        for(int i=n;i>=1;i--)
        {
            ans=b[i]/(a[i]+ans);
        }
        printf("Case #%d: ",_);
        printf("%lld %lld\n",ans.a,ans.b);
    }

    return 0;
}
View Code

 

posted @ 2018-09-19 12:41  LMissher  阅读(124)  评论(0编辑  收藏  举报