HDU 1713 相遇周期(水)
水题,不解释。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <map> 6 #include <queue> 7 #define ll __int64 8 using namespace std; 9 ll gcd(ll a,ll b) 10 { 11 return b == 0?a:gcd(b,a%b); 12 } 13 int main() 14 { 15 int t; 16 ll a,b,c,d,gc,gd; 17 scanf("%d",&t); 18 while(t--) 19 { 20 scanf("%I64d/%I64d%I64d/%I64d",&a,&b,&c,&d); 21 gc = b*d/gcd(b,d); 22 gd = (a*gc/b)*(c*gc/d)/gcd(a*gc/b,c*gc/d); 23 if(gd % gc == 0) 24 { 25 printf("%I64d\n",gd/gc); 26 } 27 else 28 { 29 printf("%I64d/%I64d\n",gd/gcd(gd,gc),gc/gcd(gd,gc)); 30 } 31 } 32 return 0; 33 }

浙公网安备 33010602011771号