#SP0000264. Số nguyên tố tiếp theo (Next Prime)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số nguyên tố tiếp theo (Next Prime)
Next Prime
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer , find the smallest prime strictly greater than . Even if is already prime, the answer must exceed it.
Input
One line containing the integer .
Output
Print one integer: the smallest prime greater than .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
1
Output
2
Explanation
The smallest prime strictly greater than is .
Example 2
Input
2
Output
3
Explanation
Although is prime, the required number must be strictly greater, hence .
Example 3
Input
42
Output
43
Explanation
and has no prime divisor among , so the answer is .
Example 4
Input
1337
Output
1361
Explanation
Every even number from through is divisible by . The odd numbers are also composite:
- , , .
- , , .
- , , .
- , .
Thus no integer between and is prime. Since , checking the primes is sufficient; none divides . Therefore the first prime greater than is .