mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-05 13:38:47 +00:00
23 lines
470 B
C++
23 lines
470 B
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int n, q, k, p, primes[100000005];
|
|
bool not_prime[100000005];
|
|
|
|
int main() {
|
|
cin >> n >> q;
|
|
for (int i = 2; i <= n; i++) {
|
|
if (!not_prime[i]) primes[++p] = i;
|
|
for (int j = 1; primes[j] * i <= n; j++) {
|
|
not_prime[primes[j] * i] = true;
|
|
if (i % primes[j] == 0) break;
|
|
}
|
|
}
|
|
while (q--) {
|
|
cin >> k;
|
|
cout << primes[k] << endl;
|
|
}
|
|
return 0;
|
|
}
|