PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000007. Số nguyên tố không nhỏ hơn X (Next 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
Số nguyên tố không nhỏ hơn X (Next Prime)
Next Prime
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer , find the smallest prime number satisfying . No prime number may satisfy . If is already prime, the answer is .
Input
A single line containing the integer .
Output
Print one integer : the smallest prime number greater than or equal to .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
20
Output
23
Explanation
The values and are even, while ; none is prime. The next value, , has no divisor between and , so the answer is .
Input
2
Output
2
Explanation
is prime, so the smallest eligible prime is itself.
Input
99992
Output
100003
Explanation
Every integer in is composite, and is prime. Hence is the first eligible value.