From 5a06e2f5d6e469eefbb8aff5b84dd0adc5aba7e4 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 11 Nov 2021 18:39:02 +0800 Subject: [PATCH] =?UTF-8?q?P3383=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E7=BA=BF=E6=80=A7=E7=AD=9B=E7=B4=A0=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/62272937 --- Luogu/P3383/P3383.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Luogu/P3383/P3383.cpp diff --git a/Luogu/P3383/P3383.cpp b/Luogu/P3383/P3383.cpp new file mode 100644 index 00000000..2128d0dd --- /dev/null +++ b/Luogu/P3383/P3383.cpp @@ -0,0 +1,22 @@ +#include + +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; +}