結果

問題 No.458 異なる素数の和
ユーザー smz_8110smz_8110
提出日時 2017-04-17 16:49:38
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 297 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 42,060 KB
最終ジャッジ日時 2023-09-26 10:46:21
合計ジャッジ時間 5,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,084 KB
testcase_01 AC 140 ms
26,564 KB
testcase_02 AC 146 ms
27,976 KB
testcase_03 AC 96 ms
18,640 KB
testcase_04 AC 98 ms
19,168 KB
testcase_05 AC 198 ms
38,516 KB
testcase_06 AC 141 ms
27,048 KB
testcase_07 AC 80 ms
15,268 KB
testcase_08 AC 201 ms
38,220 KB
testcase_09 AC 90 ms
16,660 KB
testcase_10 AC 81 ms
15,176 KB
testcase_11 AC 216 ms
41,992 KB
testcase_12 AC 79 ms
15,048 KB
testcase_13 WA -
testcase_14 AC 80 ms
15,084 KB
testcase_15 AC 81 ms
15,188 KB
testcase_16 AC 91 ms
17,292 KB
testcase_17 AC 79 ms
15,164 KB
testcase_18 AC 79 ms
15,016 KB
testcase_19 AC 79 ms
15,024 KB
testcase_20 AC 79 ms
15,300 KB
testcase_21 AC 79 ms
15,088 KB
testcase_22 AC 79 ms
15,132 KB
testcase_23 AC 79 ms
15,268 KB
testcase_24 AC 79 ms
15,124 KB
testcase_25 AC 78 ms
15,080 KB
testcase_26 AC 78 ms
15,124 KB
testcase_27 AC 143 ms
26,824 KB
testcase_28 AC 216 ms
42,060 KB
testcase_29 AC 83 ms
15,780 KB
testcase_30 AC 123 ms
23,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
r=[0,0]
2.upto(Math.sqrt(N)){|i|(i+i).step(N,i){|j|r[j]=0} unless r[i]}
m=[]
r.each_with_index{|v,i|m<<i unless v}
e={0=>0}
m.each{|v|
  f=true
  g=e.clone
  e.each{|w,x|
    z=v+w
    if z<=N&&(!g[z]||g[z]<x+1)
      g[z]=x+1
      f=false
    end
  }
  break if f
  e=g
}
p e[N]||-1
0