PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000265. Lại là số nguyên tố (Previous 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
Lại là số nguyên tố (Previous Prime)
Previous Prime
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer , find the largest prime strictly smaller than . Even when is prime, it cannot be chosen. As , an answer always exists.
Input
One line containing the integer .
Output
Print a single integer: the greatest prime below .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
5
Output
3
Explanation
Primes below are and ; the largest is .
Example 2
Input
10
Output
7
Explanation
The primes below are ; therefore output .
Example 3
Input
17
Output
13
Explanation
cannot be chosen because the answer must be strictly smaller. Among , the closest prime is .