結果

問題 No.458 異なる素数の和
ユーザー masashi0217masashi0217
提出日時 2021-03-31 02:15:37
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,549 ms / 2,000 ms
コード長 366 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 15,732 KB
最終ジャッジ日時 2023-08-20 21:59:24
合計ジャッジ時間 51,706 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,536 ms
15,724 KB
testcase_01 AC 1,535 ms
15,640 KB
testcase_02 AC 1,528 ms
15,664 KB
testcase_03 AC 1,532 ms
15,464 KB
testcase_04 AC 1,525 ms
15,512 KB
testcase_05 AC 1,547 ms
15,684 KB
testcase_06 AC 1,539 ms
15,584 KB
testcase_07 AC 1,534 ms
15,552 KB
testcase_08 AC 1,535 ms
15,476 KB
testcase_09 AC 1,531 ms
15,684 KB
testcase_10 AC 1,549 ms
15,544 KB
testcase_11 AC 1,530 ms
15,460 KB
testcase_12 AC 1,534 ms
15,572 KB
testcase_13 AC 1,534 ms
15,492 KB
testcase_14 AC 1,538 ms
15,572 KB
testcase_15 AC 1,546 ms
15,708 KB
testcase_16 AC 1,540 ms
15,628 KB
testcase_17 AC 1,531 ms
15,700 KB
testcase_18 AC 1,544 ms
15,504 KB
testcase_19 AC 1,536 ms
15,584 KB
testcase_20 AC 1,539 ms
15,732 KB
testcase_21 AC 1,533 ms
15,472 KB
testcase_22 AC 1,539 ms
15,544 KB
testcase_23 AC 1,530 ms
15,692 KB
testcase_24 AC 1,529 ms
15,540 KB
testcase_25 AC 1,544 ms
15,516 KB
testcase_26 AC 1,535 ms
15,500 KB
testcase_27 AC 1,534 ms
15,712 KB
testcase_28 AC 1,537 ms
15,460 KB
testcase_29 AC 1,541 ms
15,460 KB
testcase_30 AC 1,531 ms
15,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'
n = gets.chomp.to_i
#素数を固定して回す
max = 20001
dp = Array.new(max,0)
a = Prime.each(max).to_a.reverse.map(&:to_i)

a.each do |i|
    dp[i] += 1
end
a.each do |i|
    (max-1-i).downto(i+1) do |j|
        if dp[j] > 0
            dp[i+j] = [dp[j]+1,dp[i+j]].max
        end
    end
end
if dp[n] == 0
    puts "-1"
else
    puts dp[n]
end
0