标签:light oj lightoj basic math 数学 大数高精度
高精度乘低精度
vis数组存的是质因子i的数量
#include<bits/stdc++.h>
using namespace std;
const int base=1e8;
const int MAXN=505;
long long a[MAXN];
int vis[10005];
int len;
void multi(long long a[],int x)
{
for(int i=len; i>=0; --i)
a[i]*=x;
for(int i=0; i<len; i++)
{
a[i+1]+=a[i]/base;
a[i]%=base;
}
if(a[len]>base)
{
a[len+1]+=a[len]/base;
a[len]%=base;
len++;
}
}
void print(void)
{
printf("%d",a[len]);
for(int i=len-1; i>=0; --i)
{
printf("%08d",a[i]);
}
puts("");
}
int main(void)
{
//freopen("in","r",stdin);
//freopen("out","w",stdout);
int t,Case=0;
int n,x;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(vis,0,sizeof(vis));
a[0]=1;
len=0;
while(n--)
{
scanf("%d",&x);
for(int i=2; x>1; i++)
{
int cnt=0;
while(x%i==0)
{
cnt++;
x/=i;
}
vis[i]=max(vis[i],cnt);
}
}
printf("Case %d: ",++Case);
for(int i=2; i<10005; i++)
{
while(vis[i]--)
multi(a,i);
}
print();
}
return 0;
}
标签:light oj lightoj basic math 数学 大数高精度
原文地址:http://blog.csdn.net/loolu5/article/details/45868341