hdu 相遇周期

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int t,a,b,c,d;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         scanf("%d/%d %d/%d",&a,&b,&c,&d);
13         int m=__gcd(a,b);
14         a/=m;b/=m;
15         int x=__gcd(c,d);
16         c/=x;d/=x;
17         if(__gcd(b,d)==1)
18         {
19             printf("%d
",a/(__gcd(a,c))*c);
20         }
21         else
22             printf("%d/%d
",a/(__gcd(a,c))*c,__gcd(b,d));
23     }
24     return 0;
25 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/3652903.html