PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000269. Tích K số nguyên tố liên tiếp (Consecutive Prime Product)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tích K số nguyên tố liên tiếp (Consecutive Prime Product)
Consecutive Prime Product
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the sequence of all prime numbers in strictly increasing order: . A product of consecutive primes is .
Given and , find the largest such product that does not exceed . If none exists, print -1.
Input
One line contains two integers and .
Output
Print the maximum product of consecutive primes not exceeding , or -1 if no product is possible.
Subtasks
- Subtask 1 (20 points): and .
- Subtask 2 (30 points): and .
- Subtask 3 (50 points): and .
Examples
Example 1
Input
100 4
Output
-1
Explanation
The smallest product of consecutive primes is , so print -1.
Example 2
Input
110 3
Output
105
Explanation
The first products of three consecutive primes are , , and . Since , print .
Example 3
Input
1000 3
Output
385
Explanation
The first three products are , and the next one equals , so the answer is .