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 200908061078 at 2010-07-27 10:28:53
#include<stdio.h>
main()
{
	int i,n,a[10000],j=1,k=0,x,count,sum;
	a[0]=2;
	for(n=3;n<10000;n=n+2)
	{
		for(i=2;i<n;i++)
			if(n%i==0)
			break;
		if(i>=n)
			a[j++]=n;	
	}
	

	while(1)
	{
		scanf("%d",&x);
		if(x==0)
			break;
		i=count=0;
	   while(1)
	   {	
		sum=0;
	
		for(k=i;k<x;k++)
		{
			sum+=a[k];
			if(sum>x)
				break;
			if(sum==x)
				count++;
			
		}
		i++;
		if(i>x)
			break;
      }
      printf("%d\n",count);
	}
		
}

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