lightOJ-1024
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN = 100010;
int ans[MAXN], cnt[MAXN], len;
int fun(int x,int y)//x代表因子 y代表这个因子出现的次数
{
int t=1;
for(int i=1; i<=y; i++)
t*=x;
return t;
}
void multiply(int fact)
{
//cout << fact << "**" << endl;
for(int i = 0; i < len; i ++) ans[i] *= fact;//先把每位乘以每一个新的因子
for(int i = 0; i < len; i ++)//再重新分解一遍只储存每个位数
{
ans[i+1] += ans[i]/10;
ans[i] %= 10;
}
// for(int i=len;i>=0;i--)
// cout << ans[i] <<":";
// cout << endl;
int tmp = ans[len];
while(tmp)//分解最后那个数,因为最后可能不是一位数,大数长度增加就是在这里记录的
{
ans[len++] = tmp%10;
tmp /= 10;
}
// for(int i=len;i>=0;i--)
// cout << ans[i] <<"^";
// cout << endl;
}
int main()
{
int t, CASE(0), n, tmp;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(cnt, 0, sizeof cnt);
memset(ans, 0, sizeof ans);
for(int i = 0; i < n; i ++)
{
scanf("%d", &tmp);
int fact = 2;
while(tmp != 1)//找出所有的因子,并储存因子出现的次数
{
int num = 0;
while(tmp % fact == 0) num ++, tmp /= fact;
cnt[fact] = max(cnt[fact], num);//记录出现次数
fact++;
}
}
ans[0] = len = 1;
for(int i = 2; i <= 10000; i ++) if(cnt[i]) multiply(fun(i, cnt[i]));
printf("Case %d: ", ++CASE);//上面的循环是把所有最高次因子乘起来
for(int i = len - 1; i > 0; i --) printf("%d", ans[i]);//按位输出大数
printf("%d\n", ans[0]);
}
return 0;
}
/*
5 4 3 5 7 11
*/
网上学来的,自己加了注释便于理解。->http://blog.csdn.net/zyz_3_14159/article/details/52810165