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 13227183 at 2008-07-24 15:26:53 on Problem 2739
#include<iostream>
int main()
{
	int k=1,i,j,a[10000];
	int b,sum=0;//输入b来测试
    int c=0;//统计个数
	scanf("%d",&b);
	a[0]=2;
	
	while(b!=0)
	{
	 for(i=3;i<b+1;i++)
	 {
 	   for(j=2;j<i;j++)
 	   {
 	   	if(i%j==0)
 	   	break;
 	   }	
 	   if(j==i)
 	   {
 	   	a[k]=i;
 	   	k++;
 	   }
	 }
	  for(j=0;j<=b;j++)
	   {
	   	 for(i=j;sum<b;i++)
	   	 {sum=sum+a[i];}
	  	 if(sum==b){c++;}
	  	 sum=0;
	   }
	   printf("%d\n",c);
	   c=0;
	   k=1;
	   scanf("%d",&b);
	}
	return 0;
}

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