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

#SP0000196. Chọn nguyên tố có số dư lớn nhất (Less Prime)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chọn nguyên tố có số dư lớn nhất (Less Prime)

Less Prime

Phuoc Hung OJ ID: PRIME000201
Original source: UVa 10852

Problem statement

For a given integer nn, find a prime p≤np\le n that maximizes the remainder n mod pn\bmod p.

Input

One integer nn.

Output

Print a prime p≤np\le n maximizing n mod pn\bmod p.

Subtasks

  • Subtask 1 (20 points): 100≤n≤500100\le n\le 500.
  • Subtask 2 (30 points): 501≤n≤3 000501\le n\le 3\,000.
  • Subtask 3 (50 points): 3 001≤n≤10 0003\,001\le n\le 10\,000.

Example

Input

100

Output

53

Explanation: 100 mod 53=47100\bmod53=47 is the maximum possible remainder among prime divisors-as-moduli p≤100p\le100.