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

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

1 lộ trình

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: 2,3,5,7,11,13,17,…2,3,5,7,11,13,17,\ldots. A product of KK consecutive primes is pipi+1⋯pi+K−1p_i p_{i+1}\cdots p_{i+K-1}.

Given NN and KK, find the largest such product that does not exceed NN. If none exists, print -1.

Input

One line contains two integers NN and KK.

Output

Print the maximum product of KK consecutive primes not exceeding NN, or -1 if no product is possible.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1071\le N\le10^7 and 3≤K≤103\le K\le10.
  • Subtask 2 (30 points): 1≤N≤10121\le N\le10^{12} and 3≤K≤103\le K\le10.
  • Subtask 3 (50 points): 1≤N≤264−11\le N\le2^{64}-1 and 3≤K≤103\le K\le10.

Examples

Example 1

Input

100 4

Output

-1

Explanation

The smallest product of 44 consecutive primes is 2⋅3⋅5⋅7=210>1002\cdot3\cdot5\cdot7=210>100, so print -1.

Example 2

Input

110 3

Output

105

Explanation

The first products of three consecutive primes are 3030, 105105, and 385385. Since 105≤110<385105\le110<385, print 105105.

Example 3

Input

1000 3

Output

385

Explanation

The first three products are 30,105,38530,105,385, and the next one equals 7⋅11⋅13=1001>10007\cdot11\cdot13=1001>1000, so the answer is 385385.