现在的位置: 首页 > 综合 > 正文

hdu 1019 数学

2013年10月24日 ⁄ 综合 ⁄ 共 338字 ⁄ 字号 评论关闭

直接求就行

AC代码如下:

#include <iostream>
using namespace std;

int gcd( int a, int b ){
	int temp;
	if( a < b ){
		temp = a;
		a = b;
		b =temp;
	}
	while( b != 0 ){
		temp = a % b;
		a = b;
		b = temp;
	}
	return a;
}

int lcm( int a, int b ){
	int temp;
	temp = gcd( a, b );
	return a / temp * b;
}

int main(){
	int T, n, result, temp;
	cin >> T;
	while( T-- ){
		cin >> n;
		result = 1;
		while( n-- ){
			cin >> temp;
			result = lcm( result, temp );
		}
		cout << result << endl;
	}
	return 0;
}

 

抱歉!评论已关闭.