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

1A(给打表大仙跪下)

Posted by zhangshiyi at 2021-07-20 22:16:51 on Problem 2739
#include<iostream>
#include<cmath>
using namespace std;
const int N=10009;
int nP,p[N];
bool isprime(int x) {
	if (x<2) return 0;
	for (int i=2;i<=(int)sqrt(x);++i)
		if (x%i==0) return 0;
	return 1;
}
void shuffle() {
	for (int i=1;i<=10000;++i)
		if (isprime(i)) p[++nP]=i;
}
int main() {
	shuffle();
	int x;
	while (cin>>x) {
		if (x==0) return 0;
		int ans=0;
		for (int l=1;l<=nP;++l) {
			int cnt=0,r=l;
			for (;r<=nP&&cnt<x;++r)
				cnt+=p[r];
			if (cnt==x) ++ans;
		}
		cout<<ans<<endl;
	}
	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