luogu#P3383. 【模板】线性筛素数
【模板】线性筛素数
Background
This problem has been updated: it now asks for querying the -th smallest prime instead of primality testing.
Hint: The input/output and computation workload can be large.
- For C++: if you use
cinfor I/O, considerstd::ios::sync_with_stdio(0)for acceleration, and use'\n'for newlines. - For Java: using a linear sieve with optimized I/O can pass within the time limit, though it may be tight.
- For Python: performance varies widely by implementation; using arrays from the
numpylibrary instead of lists, together with the Sieve of Eratosthenes, can still pass within reasonable time and memory limits.
Problem Description
Given an upper bound and queries, for each query output the -th smallest prime number.
Input Format
The first line contains two positive integers , representing the query range and the number of queries.
Each of the next lines contains a positive integer , asking for the -th smallest prime.
Output Format
Output lines, each containing a single integer as the answer.
100 5
1
2
3
4
5
2
3
5
7
11
Hint
Constraints
For of the testdata, , , and it is guaranteed that the requested primes do not exceed .
Data by NaCly_Fish.
Translated by ChatGPT 5