标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2465 Accepted Submission(s): 1236
题目分析:题目输入c1/t1 c2/t2 ,也就是速度的分数形式,转换成:c1*t2/(t1*t2), c2*t1/( t1*t2 ); 这时候我们只需要求出分子的最小公倍数k,然后k/( t1*t2 )就是题目求的周期
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; __int64 gcd(__int64 x,__int64 y){ __int64 tx=x>y?x:y; __int64 ty=x<y?x:y; if(ty==0) return tx; else gcd(ty,tx%ty); } __int64 lcm(__int64 x,__int64 y){ return x*y/gcd(x,y); } int main(){ int t; scanf("%d",&t); while(t--){ __int64 a,b,c,d; scanf("%I64d/%I64d %I64d/%I64d",&a,&b,&c,&d); a*=d; c*=b; b*=d; __int64 temp=lcm(a,c); __int64 temp1=gcd(temp,b); temp/=temp1; b/=temp1; if(b==1) printf("%I64d\n",temp); else printf("%I64d/%I64d\n",temp,b); } return 0; }
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4668465.html