【转】http://blog.youkuaiyun.com/zxy_snow/article/details/6011166
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <memory.h>
#define MAX 10001
using namespace std;
long long int gcd(long long int x,long long int y)
{
return y == 0? x : gcd(y,x%y);
}
int main(void)
{
int num[MAX];
int ncases,n;
scanf("%d",&ncases);
while( ncases -- )
{
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%d",&num[i]);
if( n == 1 )
{
printf("%d/n",num[0]);
continue;
}
int temp = gcd(num[0],num[1]);
if(temp == 0 )
{
printf("%d/n",temp);
continue;
}
temp = num[0]/temp*num[1];
for(int i=2; i<n; i++)
{
int x = gcd(temp,num[i]);
if( x == 0 )
{
temp = 0;
break;
}
temp = temp/x*num[i];
}
printf("%d/n",temp);
}
return 0;
}