选拔赛c题武器大师的宝贝

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll getshu(ll a,ll c)
{
    while(1)
    {if(c%a==0)
        {return a;break;}
        ll tep=c;
        c=a;
        a=tep%a;}
}
int main()
{
    int t;
cin>>t;
while(t--)
{
    ll fl,fr,sl,sr;
    cin>>fl>>fr>>sl>>sr;
    ll ans=0;
    if(fr<sl||sr<fl)cout<<"0/1"<<endl;
   else
   {
        if(fl<=sl&&fr>=sl)
   {
       if(fr<=sr)ans+=fr-sl+1;
       else ans+=sr-sl+1;
   }
   if(sl<fl&&sr>=fl)
   {
       if(sr<=fr)ans+=sr-fl+1;
       else ans+=fr-fl+1;
   }
        ll f1=fr-fl+1,f2=sr-sl+1;
        ll fz=f1*f2;
        ll chu=getshu(ans,fz);
        cout<<ans/chu<<"/"<<fz/chu<<endl;
   }
}
}

猜你喜欢

转载自blog.csdn.net/weixin_43331783/article/details/88362615
今日推荐