Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪为牛人帮忙查查错,!!

Posted by lovebit at 2006-09-24 22:49:28 on Problem 3002
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator