设为首页 加入收藏

TOP

HDU 1019 Least Common Multiple 数学题解
2015-07-20 18:03:47 来源: 作者: 【 】 浏览:3
Tags:HDU 1019 Least Common Multiple 数学 题解

求一组数据的最小公倍数。

先求公约数在求公倍数,利用公倍数,连续求所有数的公倍数就可以了。

#include 
  
   
int GCD(int a, int b)
{
	return b? GCD(b, a%b) : a;
}

inline int LCM(int a, int b)
{
	return a / GCD(a, b) * b;
}

int main()
{
	int T, m, a, b;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d %d", &m, &a);
		while (--m)
		{
			scanf("%d", &b);
			a = LCM(a, b);
		}
		printf("%d\n", a);
	}
	return 0;
}
  




】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu4882-ZCC Loves Codefires(贪.. 下一篇HDOJ 4882 ZCC Loves Codefires

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: