1. 程式人生 > >CCPC2016長春B (hdu 5912 Fraction)

CCPC2016長春B (hdu 5912 Fraction)

cti microsoft friend aps alt n) c++ sca test

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

CCPC2016長春B (hdu 5912 Fraction)