CF923A.Primal Sport

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob begin their day with a quick game. They first choose a starting number X0>=3X_{0}>=3 and try to reach one million by the process described below.

Alice goes first and then they take alternating turns. In the ii -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 Xi>=Xi1X_{i}>=X_{i-1} such that pp divides XiX_{i} . Note that if the selected prime pp already divides Xi1X_{i-1} , then the number does not change.

Eve has witnessed the state of the game after two turns. Given X2X_{2} , help her determine what is the smallest possible starting number X0X_{0} . Note that the players don't necessarily play optimally. You should consider all possible game evolutions.

输入格式

The input contains a single integer X2X_{2} ( 4<=X2<=1064<=X_{2}<=10^{6} ). It is guaranteed that the integer X2X_{2} is composite, that is, is not prime.

输出格式

Output a single integer — the minimum possible X0X_{0} .

输入输出样例

  • 输入#1

    14
    

    输出#1

    6
    
  • 输入#2

    20
    

    输出#2

    15
    
  • 输入#3

    8192
    

    输出#3

    8191
    

说明/提示

In the first test, the smallest possible starting number is X0=6X_{0}=6 . One possible course of the game is as follows:

  • Alice picks prime 5 and announces X1=10X_{1}=10
  • Bob picks prime 7 and announces X2=14X_{2}=14 .

In the second case, let X0=15X_{0}=15 .

  • Alice picks prime 2 and announces X1=16X_{1}=16
  • Bob picks prime 5 and announces X2=20X_{2}=20 .
首页