PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000068. Tìm số nguyên tố thứ K (Finding the Kth Prime)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm số nguyên tố thứ K (Finding the Kth Prime)
Finding the Kth Prime
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
List the primes in increasing order, , indexed from (so the first prime is ). Given independent queries, answer query with the value of the -th prime. Preserve the input query order.
Input
The first line contains integer . Each of the next lines contains one integer .
Output
Print exactly lines; line is the -th prime.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
7
1
10
100
1000
10000
100000
1000000
Output
2
29
541
7919
104729
1299709
15485863
Explanation
The first prime is and the tenth is . Positions give , respectively. There are exactly seven output lines, matching the seven queries.