A11468 | Primal Sport
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alice and Bob begin their day with a quick game. They first choose a starting number $X_{0}>=3$ and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the $i$ -th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime $p<X_{i-1}$ and then finds the minimum $X_{i}>=X_{i-1}$ such that $p$ divides $X_{i}$ . Note that if the selected prime $p$ already divides $X_{i-1}$ , then the number does not change.
Eve has witnessed the state of the game after two turns. Given $X_{2}$ , help her determine what is the smallest possible starting number $X_{0}$ . Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
Alice goes first and then they take alternating turns. In the $i$ -th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.
Formally, he or she selects a prime $p<X_{i-1}$ and then finds the minimum $X_{i}>=X_{i-1}$ such that $p$ divides $X_{i}$ . Note that if the selected prime $p$ already divides $X_{i-1}$ , then the number does not change.
Eve has witnessed the state of the game after two turns. Given $X_{2}$ , help her determine what is the smallest possible starting number $X_{0}$ . Note that the players don't necessarily play optimally. You should consider all possible game evolutions.
输入格式
The input contains a single integer $X_{2}$ ( $4<=X_{2}<=10^{6}$ ). It is guaranteed that the integer $X_{2}$ is composite, that is, is not prime.
输出格式
Output a single integer — the minimum possible $X_{0}$ .
输入输出样例
输入 #1
14
输出 #1
6
输入 #2
20
输出 #2
15
输入 #3
8192
输出 #3
8191
In the first test, the smallest possible starting number is $X_{0}=6$ . One possible course of the game is as follows:
- Alice picks prime 5 and announces $X_{1}=10$
- Bob picks prime 7 and announces $X_{2}=14$ .
In the second case, let $X_{0}=15$ .
- Alice picks prime 2 and announces $X_{1}=16$
- Bob picks prime 5 and announces $X_{2}=20$ .
- Alice picks prime 5 and announces $X_{1}=10$
- Bob picks prime 7 and announces $X_{2}=14$ .
In the second case, let $X_{0}=15$ .
- Alice picks prime 2 and announces $X_{1}=16$
- Bob picks prime 5 and announces $X_{2}=20$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted