#include<iostream>
using namespace std;
int LCM(int a,int b);
int GCD(int a,int b);
int main(void)
{
int count;
cin>>count;
int n;
int temp;
int r;
while(count--)
{
cin>>n;
r=1;
for(int i=0;i<n;i++)
{
cin>>temp;
r=LCM(temp,r);
}
cout<<r<<endl;
}
return 0;
}
int LCM(int a,int b)
{
return a/GCD(a,b)*b;//如果写成return a*b/GCD(a,b)就可能会溢出
}
int GCD(int a,int b)
{
int temp;
while(b)
{
temp=a%b;
a=b;
b=temp;
}
return a;
}
1019 Least Common Multiple
最新推荐文章于 2018-05-06 19:55:38 发布