Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
970 B
1
Indexable
Never
#include <iostream>
#include<vector>
#include<stdio.h>
using namespace std;

bool prime[10001];
vector<int> primes;
void findprime(){ //建構質數表
    for (int i=0;i<10001;i++){//
        prime[i]=true;
    }
    prime[0]=false;
    prime[1]=false;
    for (int i=2; i<10001; i++){
            if (prime[i]){
              if((long long)i*i<10001){//
                for(int m=i*i; m<10001; m+=i)
                  prime[m] = false;
              }
              primes.push_back(i);//儲存已知的質數
        }
    }
  }
int main()
{
    int n;
    findprime();
    while(cin>>n){
            if(n==0) break;
          int l=0,ans=0,sum=0;
          for(int r=0;n>=primes[r];r++){
              sum+=primes[r];
              while(sum>n){
                  sum-=primes[l++];
             }
              if(sum==n){
                 ans++;
              }
         }
          cout<<ans<<endl;
    }
    return 0;
}