欧拉筛处理2-1e4的质数,再用尺取法即可
// Problem: Sum of Consecutive Prime Numbers
// Contest: POJ - Japan 2005
// URL: http://poj.org/problem?id=2739
// Memory Limit: 65 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)#include<iostream>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
const int N=1e4+9;
ll perfix[N];
int x;
vector<ll> prime;
bitset<N> vis;
void euler(){vis[0]=vis[1]=true;for(int i=2;i<=10000;i++){if(!vis[i]){prime.push_back(i);}for(int j=0;j<(int)prime.size() && i*prime[j]<=10000;j++){vis[i*prime[j]]=true;if(i%prime[j]==0){break;}}}
}
void solve(){ll ans=0;int l=0,r=0,ed=(int)prime.size();ll sum=0;while(1){while(sum<x && r<=ed){sum+=prime[r++];}if(sum<x){break;}if(sum==x){ans++;}sum-=prime[l++];}cout<<ans<<'\n';
}
int main(){euler();cin>>x;while(x){solve();cin>>x;}return 0;
}