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

baneHunter打表

Posted by 1340502116 at 2016-05-09 21:41:39 on Problem 2739
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=10005;
bool isPrime[MAXN];
int prime[MAXN],top;
void init()
{
	memset(isPrime,true,sizeof(isPrime));
	for(int i=2;i<MAXN;i++)
	{
		if(isPrime[i])
		{
			prime[top++]=i;
			for(int j=i+i;j<MAXN;j+=i)
				isPrime[j]=false;
		}
	}
}
int counter[MAXN];
int total[MAXN];
void solve()
{
	total[1]=prime[0];
	for(int i=2;i<=top;i++)
		total[i]=total[i-1]+prime[i-1];
	for(int l=1;l<=top;l++)
	{
		for(int i=1;i+l<=top+1;i++)
		{
			int sum=total[i+l-1]-total[i-1];
			if(sum<MAXN)
				counter[sum]++;
		}
	}
}
int main()
{
	init();
	solve();
	int n;
	while(scanf("%d",&n)!=EOF&&n!=0)
	{
		printf("%d\n",counter[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