結果
| 問題 | No.458 異なる素数の和 |
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2018-04-03 03:56:04 |
| 言語 | Ruby (4.0.2) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 383 bytes |
| 記録 | |
| コンパイル時間 | 494 ms |
| コンパイル使用メモリ | 8,704 KB |
| 実行使用メモリ | 22,656 KB |
| 最終ジャッジ日時 | 2026-03-12 22:51:02 |
| 合計ジャッジ時間 | 12,415 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 1 RE * 1 |
コンパイルメッセージ
Main.rb:28: warning: ambiguous first argument; put parentheses or a space even after `-` operator Main.rb:5: warning: assigned but unused variable - t Syntax OK
ソースコード
require 'prime'
n=gets.to_i
dp=[0]*(n+2)
x=Prime.each(n).to_a
t=n/2+2
sum=0
while x[0]*2<=n
e=x.shift
sum+=e
sum=[n,sum].min
(sum-e+1).times{|i|
p2=(sum-e+1)-i
p3=e+p2
next if p3>n
if dp[p2]>0 && dp[p3]<dp[p2]+1
dp[p3]=dp[p2]+1
end
}
dp[e]=[dp[e],1].max
end
ans=dp[n]
x.each{|e|
p1=n-e
break if p1<0
ans=[ans,dp[p1]+1].max
}
if ans<2
puts -1
else
puts ans
end
horiesiniti