解题思路:求两个数的最小公倍数=两个数相乘,再处理最大公约数。最大公约数用辗转相除术。
最大公约数和最小公倍数说明见下面连接:
https://jingyan.baidu.com/article/0964eca21e03ac8285f53602.html
http://blog.csdn.net/qq_31828515/article/details/51812154
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <stdio.h>
using namespace std;
int gcd(int a,int b){ //最大公约数,辗转相除术
if(b==0){
return a;
} else{
return gcd(b,a%b);
}
}
int main() {
int t;
int n;
int a,tmp;
int output;
cin >> t;
while (t--) {
cin >> n;
cin >> a;
tmp=a;
for(int i=1;i<n;i++){
cin >> a;
tmp=tmp/gcd(tmp,a)*a; //最小公倍数等于两个数相乘,再处理最大公约数
}
cout << tmp << endl;
}
return 0;
}