先埃式筛法筛出10000以内所有素数,再尺取
import java.util.Scanner;
public class POJ_2739 {
static int n;
static int[] prime=new int[10005];
static boolean[] is_prime=new boolean[100005];
static void sieve(){
int p=0;
for (int i = 0; i <= 10000; i++) {
is_prime[i]=true;
}
is_prime[0]=is_prime[1]=false;
for (int i = 2; i <= 10000; i++) {
if(is_prime[i]){
prime[p++]=i;
for (int j = 2*i; j <= 10000; j+=i) {
is_prime[j]=false;
}
}
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
sieve();
while(true){
n=sc.nextInt();
if(n==0)break;
solve(n);
}
}
private static void solve(int n) {
int ans=0,t=0,sum=0,s=0;
for(;;){
while(t<n&&sum<n){
sum+=prime[t++];
}
if(sum<n)break;
if(sum==n){
ans++;
}if(t==n)break;
sum-=prime[s++];
}
System.out.println(ans);
}
}