forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreseto.cpp
42 lines (33 loc) · 761 Bytes
/
reseto.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
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<bool> v;
v.resize(n+1, true);
v[0] = false;
v[1] = false;
int crosses = 0;
for(int i = 2; i <= n; i++) {
// If not prime, continue
if(!v[i]) {
continue;
}
// If prime, cross it out, then sieve
for(int j = i; j <= n; j+=i) {
// If crossed, skip
if(!v[j]) {
continue;
}
// Otherwise, cross
v[j] = false;
crosses++;
// If crossed enough, quit
if(crosses == k) {
cout << j << endl;
return 0;
}
}
}
}