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 cycpp at 2008-07-26 10:23:15 on Problem 2739
In Reply To:好久没打过表了…… Posted by:summery at 2006-08-07 18:39:41
n从2到10000都输出了真确的结果  但就是RTE!!!
我也只好打表了  还请教各位高人能否指出为什么会RTE(本机已正常运行)
#include <iostream>
#include <math.h>
using namespace std;
int susu(int n)
{
	if(n<=3)return 1;
	if(n%2==0)return 0;
	int middle=(int)sqrt(double(n));
	int i;
	for(i=3;i<=middle;i+=2)//奇数不能被偶数整除
	{
		if(n%i==0)break;
	}
	if(i>middle)return 1;
	else return 0;
}
int main()
{
	int p[1130]={0};
	int i,j;
	j=1;
	for(i=2;i<10000;i++)if(susu(i)==1)p[j++]=i;
	int n;
	cin>>n;
	while(n)
	{
		int count=0;
		i=1129;
		while(n<p[i])i--;
		j=i;
		int sum=p[i];
		while(i!=0)
		{

			if(sum==n)
			{
				count++;
				sum-=p[j];
				j--;
				i--;
				sum+=p[i];
				continue;
			}
			else	if(sum<n)
				{
					i--;
					sum+=p[i];
				}
				else 
				{
					sum-=p[j];
					j--;
				}
		}
		cout<<count<<endl;
		cin>>n;
	}
	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