結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2019-04-12 22:38:33 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 907 ms / 2,000 ms |
| コード長 | 990 bytes |
| コンパイル時間 | 72 ms |
| コンパイル使用メモリ | 6,688 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 20:28:17 |
| 合計ジャッジ時間 | 4,905 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
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)