0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P3383 【模板】线性筛素数

https://www.luogu.com.cn/record/62272937
This commit is contained in:
Baoshuo Ren 2021-11-11 18:39:02 +08:00 committed by Baoshuo Ren
parent 8a39ab2e19
commit 5a06e2f5d6
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

22
Luogu/P3383/P3383.cpp Normal file
View File

@ -0,0 +1,22 @@
#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;
}