PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000280. Tìm số nguyên tố thứ K — nâng cao (Finding the Kth Prime (Hard))
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 — nâng cao (Finding the Kth Prime (Hard))
Finding the Kth Prime (Hard)
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
List all prime numbers in strictly increasing order, starting from : .
Given a positive integer , find the prime at position in this sequence. Positions are numbered starting from , so the first prime is .
Input
The only line contains a positive integer .
Output
Print the -th prime as one integer.
Subtasks
- Subtask 1 (20 points): . Time limit: s.
- Subtask 2 (30 points): . Time limit: s.
- Subtask 3 (50 points): . Time limit: s.
Examples
Example 1
Input
1
Output
2
Explanation
The prime sequence starts with , which is therefore the first prime.
Example 2
Input
10
Output
29
Explanation
The first ten primes are ; the tenth is .
Example 3
Input
100
Output
541
Explanation
There are primes at most , and itself is prime. Hence occupies position .
Example 4
Input
10000000
Output
179424673
Explanation
The prime counts satisfy and . Thus is the ten-millionth prime.