注解
1、最小公倍数=两数相乘除以最大公约数
2、n个数的最小公倍数,就是先求两个数的最小公倍数,用求出的答案再跟第三个数求最小公倍数,依次往后求。
3、本题输出结果在32位整型,但中间结果会溢出!因此必须事先定义long long int类型
代码
#include <iostream>
using namespace std;
typedef long long int LL;
LL gcd(LL a, LL b){
return a%b==0?b:gcd(b, a%b);
}
int main() {
int n;
scanf("%d", &n);
for(int i=0; i<n; i++){
int m;
scanf("%d", &m);
LL num;
scanf("%lld", &num);
for(int j=1; j<m; j++){
LL tmp;
scanf("%lld", &tmp);
num = num*tmp/gcd(num, tmp);
}
printf("%lld\n", num);
}
return 0;
}