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

这题整郁闷了 结果和打表一样 然后就WA了 然后就只好打表了。。。

Posted by allenlowesy at 2008-07-31 17:22:15 on Problem 2739
附代码  哪位大牛给看看。。。
#include <stdio.h>
#include <math.h>

int prime[10000];

int main()
{
	int i,j;

	for(i=2;i<10000;i++)
		prime[i]=1;

	for(i=2;i<100;i++)
	{
		for(j=2;j*i<10000;j++)
		{
			if(prime[i*j])
				prime[i*j]=0;
		}
	}

	j=0;
	int p[1500];

	for(i=0;i<10000;i++)
	{
		if(prime[i])
		{
			p[j]=i;
			j++;
		}
	}

	int n;

	scanf("%d",&n);

	while(n)
	{
		int sum=0;
		int total=0;
		if(prime[n])
			sum++;
		
		for(i=0;p[i]<n;i++)
		{
			total=0;
			for(j=i;p[j]<n;j++)
			{
				total+=p[j];
				if(total>n)
					break;
				else if(total==n)
				{
					sum++;
					break;
				}
			}
		}

		printf("%d\n",sum);

		scanf("%d",&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