#SP0000186. Số nguyên tố liên tiếp (tích)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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:
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 , find the largest positive integer such that:
- ;
- is a product of at least two consecutive primes.
If no such integer exists, output 1.
Input
One line containing the integer .
Output
Output the required on one line. If no valid integer exists, output 1.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
The scoring groups are part of the PHOJ Extended edition. The original LQDOJ bound is preserved.
Example
Input
150
Output
143
Explanation
is the product of two adjacent prime numbers. Other valid products below include , , , , and . No valid product strictly between and exists; thus the answer is 143.
Important: A single prime is not a valid product. The inequality is strict, so when , the answer cannot be itself.