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 wangjunyong at 2009-11-08 11:24:31 on Problem 2739
In Reply To:大家帮我看看这个代码 为什么会超时呢?? Posted by:Lemke at 2009-11-08 11:18:54
> #include<stdio.h>
> #include<math.h>
> int prime(int x,int a[])
> {
> 	int i,j,flag,k=0;
> 	for(i=2;i<=x;i++)
> 	{
> 		flag=1;
> 		for(j=2;j<=sqrt(i);j++)
> 		{
> 			if(i%j==0)
> 			{
> 				flag=0;break;
> 			}
> 		}
> 		if(flag)
> 		{
> 			a[k]=i;k++;
> 		}
> 	}
> 	return k;
> }
> int count(int x)
> {
> 	int a[170],sum[170];
> 	int i,j,done=0;
> 	int n=prime(x,a);
> 	for(i=0;i<n;i++)
> 	{
> 		sum[i]=0;
> 		for(j=i;(j<n)&&(sum[i]<x);j++)
> 		{
> 			sum[i]=sum[i]+a[j];
> 			if(sum[i]==x)
> 			{
> 				done++;
> 				break;
> 			}
> 		}
> 	}
> 	return done;
> }
> 			
> 			
> main()
> {
> 	int t[10],i=0;
> 	int x,j;
> 	while(x)
> 	{
> 		scanf("%d",&x);
> 		t[i]=count(x);i++;
> 	}
> 	for(j=0;j<i-1;j++)
> 	{
> 		printf("%d\n",t[j]);
> 	}
> 		
> 	
> }

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