标签:
2 26501/6335 18468/42 29359/11479 15725/19170
81570078/7 5431415
解析:两周期分别为a/b、c/d,既然是相遇周期,就是最早什么时间相遇,也就是两者的最小公倍数,转化一下,也就是求LCM(a, c)/ gcd(b, d)。直接求即可,不一定要用long long 或者 __int64,int也能过。注意:先把a/b和c/d尽可能的化简再求。
AC代码:
#include <cstdio> #include <iostream> using namespace std; long long gcd(long long a, long long b){ return b ? gcd(b, a % b) : a; } int main(){ // freopen("in.txt", "r", stdin); int t; long long a, b, c, d, x, y; scanf("%d", &t); while(t--){ scanf("%lld/%lld", &a, &b); scanf("%lld/%lld", &c, &d); long long fo = gcd(a, b); a /= fo; //化简 b /= fo; fo = gcd(c, d); c /= fo; d /= fo; x = (a * c) / gcd(a, c); //LCM(a, c) y = gcd(b, d); if(x % y) printf("%lld/%lld\n", x, y); else printf("%lld\n", x / y); } return 0; }
标签:
原文地址:http://blog.csdn.net/u013446688/article/details/42532585