結果

問題 No.811 約数の個数の最大化
ユーザー 👑 obakyanobakyan
提出日時 2019-04-12 22:38:33
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 913 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 22:14:58
合計ジャッジ時間 4,889 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 772 ms
4,356 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 15 ms
4,352 KB
testcase_07 AC 28 ms
4,352 KB
testcase_08 AC 229 ms
4,352 KB
testcase_09 AC 274 ms
4,348 KB
testcase_10 AC 140 ms
4,348 KB
testcase_11 AC 750 ms
4,352 KB
testcase_12 AC 99 ms
4,352 KB
testcase_13 AC 913 ms
4,356 KB
testcase_14 AC 859 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0