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 aa2985759 at 2010-11-29 20:53:49 on Problem 2739
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	bool a[12000]={0};
	vector<int>b;
	int start,num,i,j,n,sum;

	for(i=3;i<103;i+=2)
		for(j=3;j*i<12000;j+=2)
			a[i*j]=1;

	b.push_back(2);

	for(i=3;i<12000;i+=2)
		if(!a[i])
			b.push_back(i);

	scanf_s("%d",&n);

	while(n)
	{
		num=0;

		for(start=0;b[start]<=n;start++)
		{
			sum=0;
			i=start;

			while(sum<n)
				sum+=b[i++];

			if(sum==n)
				num++;
		}

		printf("%d\n",num);
		scanf_s("%d",&n);
	}
}

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