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

Re:坑。。。

Posted by yueyibo at 2016-11-21 12:37:54 on Problem 2739
In Reply To:Re:坑。。。 Posted by:yueyibo at 2016-11-21 12:32:55
> http://blog.csdn.net/luckcircle/article/details/53248376
#include<stdio.h>
#include<string.h>
const int MAX=10005;
bool isprime[10005];
int prime[1230],top=0,num[10005];
void init(){
	memset(isprime,true,sizeof(isprime));
	for(int i=2;i<MAX;i++){
		if(isprime[i]){
			prime[top++]=i;
			for(int j=i*2;j<MAX;j+=i){
				isprime[j]=false;
			}
		}
	}
}
void solve(){
	int sum;
	memset(num,0,sizeof(num));
	for(int i=0;i<top;i++){
		sum=0;
		for(int j=i;j<top;j++){
			sum=sum+prime[j];
			if(sum>10000){
				break;
			}
			num[sum]++;
		}
	}
}
int main(){
	int n;
	init();
	solve();
	while(scanf("%d",&n)!=EOF&&n){
		printf("%d\n",num[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