Codeforces Round 470 (rated, Div. 2, based on VK Cup 2018 Round 1)
B
Primal Sport
Codeforces
未评级
原题
← AC →
翻译中…

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.

翻译中…

Input

翻译中…

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

翻译中…

Output a single integer — the minimum possible $*X*_{0}$.

翻译中…

Note

翻译中…

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$.
翻译中…

样例

Input #1
14
Output #1
6
InputCopy OutputCopy
Input #2
20
Output #2
15
InputCopy OutputCopy
Input #3
8192
Output #3
8191
InputCopy OutputCopy
题目信息
题号
948B
时间限制
1.5 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。