标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2084 Accepted Submission(s): 1069
思路:求两个分式的最小公倍数,如n/a,m/b的最小公倍数 先将分母通分 为:nb/(a*b) ma/(a*b) 然后求通分后两个分子的最小公倍数lcm
那么结果就是:lcm/(a*b) 此题:若lcm%(a*b)==0 直接lcm/(a*b) 否则lcm/gcd(lcm,a*b) / (a*b)/gcd(lcm,a*b)
#include<cstdio> int Gcd(long long a,long long b)//由于参数a,b没有用龙龙,一直错 { return b==0?a:Gcd(b,a%b); } int main() { long long n,m,a,b; int T; long long lcm; scanf("%d",&T); while(T--) { scanf("%I64d/%I64d",&n,&a); scanf("%I64d/%I64d",&m,&b); lcm=(n*a*b*m)/Gcd(n*b,m*a); if(lcm%(a*b)==0) printf("%I64d\n",lcm/(a*b)); else printf("%I64d/%I64d\n",lcm/Gcd(lcm,a*b),(a*b)/Gcd(lcm,a*b)); } }
标签:
原文地址:http://www.cnblogs.com/orchidzjl/p/4274459.html