function getSoin(v) local t = {} while(1 < v) do for i = 1, v, 2 do ia = (i == 1 and 2 or i) --2, 3, 5, 7, 9, ... if(v % ia == 0) then if(t[ia] == nil) then t[ia] = 1 else t[ia] = t[ia] + 1 end v = v / ia break end end end return t end n, k = io.read("*n", "*n") soin_n = getSoin(n) tmp_i = 0 minval = 1 for soin, cnt in pairs(soin_n) do if(k <= tmp_i + cnt) then for i = 1, k - tmp_i do minval = minval * soin end break else for i = 1, cnt do minval = minval * soin end tmp_i = tmp_i + cnt end end result_j = 1 result_cnt = 0 for j = minval, n - 2 do soin_j = getSoin(j) cnt = 0 totcnt = 1 for key, val in pairs(soin_j) do totcnt = totcnt * (val + 1) if(soin_n[key] ~= nil) then cnt = cnt + math.min(soin_n[key], val) end end if(k <= cnt) then if(result_cnt < totcnt) then result_j = j result_cnt = totcnt end end end print(result_j)