結果

問題 No.458 異なる素数の和
ユーザー 👑 obakyanobakyan
提出日時 2019-04-13 22:04:37
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 683 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 5,340 KB
実行使用メモリ 23,912 KB
最終ジャッジ日時 2023-10-13 14:35:13
合計ジャッジ時間 4,526 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,836 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

furui = {}
primes = {}
-- get primes
n = io.read("*n")
for i = 2, n do
  if(not furui[i]) then
    table.insert(primes, i)
    jmax = math.floor(n / i)
    for j = 2, jmax do
      furui[j * i] = true
    end
  end
end
-- do DP
sumbox = {}
cursum = 0
sumbox[0] = 0
-- for i = 1, n do sumbox[i] = -1 end
for k, v in pairs(primes) do
  for i_sum = cursum, 0, -1 do
    if(sumbox[i_sum] ~= nil) then
      if(sumbox[i_sum + v] == nil) then
        sumbox[i_sum + v] = sumbox[i_sum] + 1
      else
        sumbox[i_sum + v] = math.max(sumbox[i_sum] + 1, sumbox[i_sum + v])
      end
    end
  end
  cursum = cursum + v
end
if(sumbox[n] == nil) then print("-1") else print(sumbox[n]) end
0