Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 int gcd(int a,int b) 5 { 6 int t,min,max; 7 min=a<b?a:b; 8 max=a<b?b:a; 9 while (t=max%min,t!=0){ max=min;min=t; } 10 return min; 11 } 12 int lcm(int a,int b) 13 { 14 int min,max,ret; 15 min=a<b?a:b; 16 max=a<b?b:a; 17 ret=max; 18 while (ret%min!=0) ret+=max; 19 return ret; 20 } 21 int main() 22 { 23 int cas,a,b,c,d,f,e,g; 24 scanf("%d",&cas); 25 while (cas--) 26 { 27 scanf("%d%d%d%d",&a,&b,&c,&d); 28 f=lcm(b,d); 29 e=a*(f/b)+c*(f/d); 30 g=gcd(e,f); 31 printf("%d %d\n",e/g,f/g); 32 } 33 return 0; 34 }
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/archive/2012/05/20/2510940.html,如需转载请自行联系原作者