PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000091. Trò chơi chọn nguyên tố (Primal Sport)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trò chơi chọn nguyên tố (Primal Sport)
Primal Sport
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Alice and Bob make two moves starting from . Each move chooses a prime strictly smaller than the current integer, then replaces the integer with the smallest multiple of not smaller than it. Alice produces and Bob produces . Given the composite integer , find the smallest possible over all legal sequences.
Input
One line contains the composite integer .
Output
Print the smallest possible starting integer .
Subtasks
- Subtask 1 (20 points): ; is composite.
- Subtask 2 (30 points): ; is composite.
- Subtask 3 (50 points): ; is composite.
Examples
Input
14
Output
6
Explanation
Start from . Alice chooses prime and rounds up to . Bob chooses prime and rounds up to . No starting integer smaller than can reach in exactly two legal moves, so the answer is .