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

 

转载于:https://www.cnblogs.com/LMissher/p/9673981.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值