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

#SP0000187. Ba số nguyên tố

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ba số nguyên tố

Three Consecutive Primes

Source: VNOJ olp_kc24_prime / OLP Sinh viên 2024
Version: Phuoc Hung OJ Extended (one dataset per execution; batched queries remain together).

Problem Statement

Given integers n,kn,k, find the largest integer m≤nm\le n whose prime factorization uses exactly three consecutive primes p1,p2,p3p_1,p_2,p_3 with positive exponents t1,t2,t3t_1,t_2,t_3, such that the number of positive divisors of mm is exactly kk. A solution is guaranteed to exist.

Input

One line containing integers n,kn,k.

Output

Print the largest valid mm.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1061\le n\le10^6, 8≤k≤27008\le k\le2700.
  • Subtask 2 (30 points): 1≤n≤10181\le n\le10^{18}, 8≤k≤248\le k\le24.
  • Subtask 3 (30 points): 1≤n≤10181\le n\le10^{18}, 8≤k≤4008\le k\le400.
  • Subtask 4 (20 points): 1≤n≤10181\le n\le10^{18}, 8≤k≤27008\le k\le2700.

Sample Input

32 8

Sample Output

30

Sample Explanation

30=2⋅3⋅530=2\cdot3\cdot5 uses three consecutive primes and has 23=82^3=8 positive divisors. No larger valid integer is at most 3232.