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

#SP0000186. Số nguyên tố liên tiếp (tích)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Số nguyên tố liên tiếp (tích)

Consecutive Prime Numbers

Source: LQDOJ — primenumbers
Version: Phuoc Hung OJ Extended

Problem Statement

Consider the increasing sequence of prime numbers:

2,3,5,7,11,13,17,19,…2,3,5,7,11,13,17,19,\ldots

A positive integer is a product of consecutive primes if it can be written as the product of at least two adjacent elements of this prime sequence.

Given a positive integer xx, find the largest positive integer yy such that:

  • y<xy<x;
  • yy is a product of at least two consecutive primes.

If no such integer exists, output 1.

Input

One line containing the integer xx.

Output

Output the required yy on one line. If no valid integer exists, output 1.

Subtasks

  • Subtask 1 (20 points): 1≤x≤1041\le x\le10^4.
  • Subtask 2 (30 points): 1≤x≤1081\le x\le10^8.
  • Subtask 3 (50 points): 1≤x≤10121\le x\le10^{12}.

The scoring groups are part of the PHOJ Extended edition. The original LQDOJ bound x≤1012x\le10^{12} is preserved.

Example

Input

150

Output

143

Explanation

143=11×13143=11\times13 is the product of two adjacent prime numbers. Other valid products below 150150 include 6=2×36=2\times3, 15=3×515=3\times5, 30=2×3×530=2\times3\times5, 35=5×735=5\times7, 77=7×1177=7\times11 and 105=3×5×7105=3\times5\times7. No valid product strictly between 143143 and 150150 exists; thus the answer is 143.

Important: A single prime is not a valid product. The inequality is strict, so when x=143x=143, the answer cannot be 143143 itself.