PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000265. Lại là số nguyên tố (Previous Prime)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lại là số nguyên tố (Previous Prime)

Previous Prime

Source: VNOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer NN, find the largest prime strictly smaller than NN. Even when NN is prime, it cannot be chosen. As N≥3N\ge3, an answer always exists.

Input

One line containing the integer NN.

Output

Print a single integer: the greatest prime below NN.

Subtasks

  • Subtask 1 (20 points): 3≤N≤100003\le N\le 10000.
  • Subtask 2 (30 points): 3≤N≤1073\le N\le 10^7.
  • Subtask 3 (50 points): 3≤N≤2323\le N\le 2^{32}.

Examples

Example 1

Input

5

Output

3

Explanation

Primes below 55 are 22 and 33; the largest is 33.

Example 2

Input

10

Output

7

Explanation

The primes below 1010 are 2,3,5,72,3,5,7; therefore output 77.

Example 3

Input

17

Output

13

Explanation

1717 cannot be chosen because the answer must be strictly smaller. Among 16,15,14,1316,15,14,13, the closest prime is 1313.