-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_1086.cpp
More file actions
36 lines (29 loc) · 836 Bytes
/
task_1086.cpp
File metadata and controls
36 lines (29 loc) · 836 Bytes
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
#include <iostream>
#include <array>
#include <vector>
constexpr int MAX_K = 15'001;
constexpr int SIEVE_LIMIT = 170'000;
int main() {
std::ios::sync_with_stdio(false);
std::array<bool, SIEVE_LIMIT> eratosthene_sieve{};
eratosthene_sieve.fill(true);
std::vector<int> prime_numbers;
prime_numbers.reserve(MAX_K);
for(int i = 2; i < SIEVE_LIMIT; i++)
if (eratosthene_sieve[i]) {
prime_numbers.push_back(i);
int64_t j = i;
while(i * j < SIEVE_LIMIT) {
eratosthene_sieve[i * j] = false;
j++;
}
}
int n;
int number_in_order;
std::cin >> n;
for(int _ = 0; _ < n; _++) {
std::cin >> number_in_order;
std::cout << prime_numbers[number_in_order - 1] << std::endl;
}
return 0;
}