結果

問題 No.7 プライムナンバーゲーム
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-06-02 12:43:23
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,215 ms / 5,000 ms
コード長 297 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 45,792 KB
最終ジャッジ日時 2024-04-09 03:46:22
合計ジャッジ時間 10,012 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 95 ms
12,160 KB
testcase_02 AC 1,215 ms
45,792 KB
testcase_03 AC 169 ms
14,080 KB
testcase_04 AC 112 ms
12,928 KB
testcase_05 AC 114 ms
12,928 KB
testcase_06 AC 422 ms
23,552 KB
testcase_07 AC 317 ms
22,272 KB
testcase_08 AC 193 ms
15,360 KB
testcase_09 AC 589 ms
26,008 KB
testcase_10 AC 95 ms
12,160 KB
testcase_11 AC 318 ms
22,400 KB
testcase_12 AC 892 ms
28,400 KB
testcase_13 AC 946 ms
30,176 KB
testcase_14 AC 1,206 ms
45,276 KB
testcase_15 AC 1,153 ms
42,208 KB
testcase_16 AC 1,065 ms
37,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n =  gets.to_i

primes = (2..n).to_a
(2..Math.sqrt(n)).each do |i|
    primes.reject!{ |v| (v % i == 0) && (i != v) }
end

dp = Array.new(n + 1, false)
dp[0] = true
dp[1] = true

(2..n).each do |i|
    dp[i] = primes.reject{|j| j > i }.any?{|j| dp[i - j] == false}
end
puts dp[n] ? "Win" : "Lose"
0