#P8795. [蓝桥杯 2022 国 A] 选素数

[蓝桥杯 2022 国 A] 选素数

Problem Description

Xiao Lan has a number xx. In each operation, Xiao Lan chooses a prime pp that is less than xx, then keeps increasing xx by 11 until xx becomes a multiple of pp (if xx is already a multiple of pp at the beginning, then xx stays unchanged).

Xiao Qiao saw the result nn obtained after Xiao Lan performed the above operation twice, and he wants to know what xx was at the beginning. If there are multiple possibilities, he wants to know the minimum possible initial value of xx. If there is no solution, it means Xiao Qiao saw it wrong; in this case, output 1-1.

Input Format

The input contains one line with an integer nn, representing the value of xx after two operations.

Output Format

Output one line with an integer representing the initial value of xx. If there are multiple solutions, output the smallest one. If there is no solution, output 1-1.

22
8

Hint

Constraints

  • For 60%60\% of the testdata, 1n50001 \leq n \leq 5000.
  • For all testdata, 1n1061 \leq n \leq 10^6.

Lanqiao Cup 2022 National Contest Group A Problem G.

Translated by ChatGPT 5