HDU 相遇周期

问题描述

2007年3月26日,在中俄两国元首的见证下,中国国家航天局局长孙来燕与俄罗斯联邦航天局局长别尔米诺夫共同签署了“中国国家航天局和俄罗斯联邦航天局关于联合探测火星-火卫一合作的协议“,确定中俄双方将于2009年年联合对火星及其卫星‘火卫一’探测进行

而卫星的英文进行这些探测的重要工具,我们的问题是已知两颗卫星的运行周期,求它们的相遇周期。

输入

输入数据的第一行为一个正整数T,表示测试数据的组数。然后是Ť组测试数据。每组测试数据包含两组正整数,用空格隔开。每组包含两个正整数,表示转Ñ圈需要的天数(6335分之26501,表示转26501圈要6335天),用\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \隔开。

产量


            对于每组测试数据,输出它们的相遇周期,如果相遇周期是整数则用整数表示,否则用最简分数表示。

样本输入

2
26501/6335 18468/42
29359/11479 15725/19170

样本输出

81570078/7
5431415
#include<cstdio>
#include<cstdlib>
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
_int64 gcd(_int64 a,_int64 b)
{
	return b == 0 ? a:gcd(b,a%b);
}
int main()
{
	int T;
	scanf_s("%d", &T);
	_int64 a, b, c, d,t;
	while (T--)
	{
		scanf_s("%I64d/%I64d %I64d/%I64d", &a, &b, &c, &d);
		while (t = gcd(a, b), t != 1)
		{
			a /= t;
			b /= t;
		}
		while (t = gcd(c, d), t != 1)
		{
			c /= t;
			d /= t;
		}
		_int64 f = (a*c / gcd(a, c));
		_int64 m = gcd(b, d);
		_int64 term;
		while (term = gcd(f, m), term != 1)
		{
			f /= term;
			m /= term;
		}
		if (m!=1)
		printf("%I64d/%I64d\n", f , m);
		else
		printf("%I64d\n",f/m);
	}
	system("pause");
		return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43411988/article/details/84261618
hdu