-
Notifications
You must be signed in to change notification settings - Fork 0
/
1644.cpp
52 lines (42 loc) · 781 Bytes
/
1644.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define N 4000005
using namespace std;
int n;
int pn[N], d[N];
vector<int> p;
queue<int> q;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i, j;
cin >> n;
pn[1] = 1;
for(i=2; i<=sqrt(n); i++){
j=i*2;
while(j<=n){
pn[j]=1;
j+=i;
}
}
for(i=1; i<=n; i++){
if(!pn[i]) p.push_back(i);
}
int ans=0, sum=0;
for(i=0; i<p.size(); i++){
sum+=p[i];
q.push(p[i]);
if(sum==n) ans++;
while(sum>n){
sum-=q.front();
q.pop();
if(sum==n) ans++;
}
}
cout << ans;
return 0;
}