forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1644.cpp
31 lines (28 loc) · 782 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
// Authored by : heheHwang
// Co-authored by : -
// http://boj.kr/d1ba3e452d8842d7a9e56640231e25f5
#include <bits/stdc++.h>
using namespace std;
const int MXN = 4000002;
vector<bool> seive(MXN, true);
vector<int> primes;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
for(int i=2; i*i<MXN; i++){
if (!seive[i]) continue;
for (int j = i * i; j < MXN; j += i)
seive[j] = false;
}
for (int i = 2; i < MXN; i++) if (seive[i]) primes.push_back(i);
primes.push_back(0);
int target, s = 0, e = 1, ans = 0, tmpSum = primes[0];
cin >> target;
while (1) {
if (tmpSum == target) ans++;
if (tmpSum <= target) tmpSum += primes[e++];
if (target < tmpSum) tmpSum -= primes[s++];
if (e == int(primes.size())) break;
}
cout << ans;
}