HDOJ1019 Least Common Multiple

原题链接

最小公倍数等于两数之积除以最大公约数。

//2014-3-11 09:03:09
#include <stdio.h>

int gcd(int a, int b){
	int t;
	while(b){
		t = a % b;
		a = b;
		b = t;
	}
	return a;
}

int main(){
	int t, n, a, s;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		s = 1;
		while(n--){
			scanf("%d", &a);
			s = s / gcd(s, a) * a;
		}
		printf("%d\n", s);
	}
	return 0;
}


posted on 2014-03-11 09:10  长木Qiu  阅读(143)  评论(0编辑  收藏  举报