| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪为牛人帮忙查查错,!!#include <stdio.h>
#include <math.h>
#define MAX 1000000000
void main()
{
int n,w,p,m,a[1010]={0},c[1000],i,j,t,z;
double r;
for(i=2;i<1000;i++)
{
if(a[i]==1) continue;
for(j=2;j<=1000;j++)
{
w=i*j;
if(w>1000) break;
else a[w]=1;
}
}
for(m=0,i=2;i<=1000;i++)
{
if(a[i]==0)
/*{*/a[m++]=i;//printf("%d ",i);}
}
//以上计算小于1000的所有素数并保存于a[0..m-1]
scanf("%d",&n);
while(n--)
{
z=0;
scanf("%d",&w);
if(w<=0) {printf("0\n");continue;}
for(i=0;i<m;i++)
c[i]=0;//记录各轮子中a[i]因子数最多数
for(i=0;i<w;i++)
{
scanf("%d",&p);
if(p<=0) {z=1;continue;}
for(j=0;z==0 && p!=1 && j<m;j++)
{
t=0;
while(p%a[j]==0)
{t++;p/=a[j];}
if(c[j]<t) c[j]=t;
}
}
if(z) {printf("0\n");continue;}
r=1;
for(i=0;i<m;i++)
{
r*=pow(a[i],c[i]);
if(r>MAX) break;
}
if(r>MAX) printf("’More than a billion.’\n");
else printf("%d\n",(int)r);
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator