Description
给出n个数,输出这n个数的最小公倍数
Input
第一行为用例组数T,每组用例占一行,首先输入一个整数n,之后输入n个整数
Output
对于每组用例,输出这n个数的最小公倍数
Sample Input
2
3 5 7 15
6 4 10296 936 1287 792 1
Sample Output
105
10296
Solution
数据量不大,两两求最小公倍数即可
Code
#include<cstdio>
#include<iostream>
using namespace std;
int gcd(int x,int y)//求gcd(x,y)
{
if(x%y) return gcd(y,x%y);
return y;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int now,next;
scanf("%d",&now);
for(int i=1;i<n;i++)
{
scanf("%d",&next);
now=next/gcd(now,next)*now;
}
printf("%d\n",now);
}
return 0;
}