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

我的是252K ……63Ms 求改进

Posted by 201330570205 at 2014-03-23 00:38:20 on Problem 2739
#include<iostream>
using namespace std;
int main()
{
	int s=0,n,K=0,M=0,a[1229]={0};
	while(cin>>n)
	{
		if(n==0) break;
		int i,j;
		for(i=2;i<=n;i++)
		{
			for(j=2;j*j<=i;j++)
				if(i%j==0) break;
			if(j*j>i) a[K++]=i;
		}
			for(i=0;i<K;i++)
			{
				for(j=i;i<K;j++)
				{
					M+=a[j];
					if(M<n)continue;
					else if(M>n){M=0;break;}
					else {s++;M=0;break;}
				}
			}
			cout<<s<<endl;
			s=0;
			K=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