結果

問題 No.7 プライムナンバーゲーム
ユーザー maimai
提出日時 2017-02-04 11:16:58
言語 Ruby
(3.2.2)
結果
AC  
実行時間 283 ms / 5,000 ms
コード長 463 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 11,432 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2023-07-24 20:46:34
合計ジャッジ時間 5,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
15,536 KB
testcase_01 AC 277 ms
15,424 KB
testcase_02 AC 278 ms
15,552 KB
testcase_03 AC 272 ms
15,400 KB
testcase_04 AC 280 ms
15,308 KB
testcase_05 AC 272 ms
15,584 KB
testcase_06 AC 264 ms
15,560 KB
testcase_07 AC 265 ms
15,360 KB
testcase_08 AC 283 ms
15,588 KB
testcase_09 AC 269 ms
15,392 KB
testcase_10 AC 269 ms
15,576 KB
testcase_11 AC 274 ms
15,328 KB
testcase_12 AC 281 ms
15,424 KB
testcase_13 AC 266 ms
15,488 KB
testcase_14 AC 267 ms
15,392 KB
testcase_15 AC 270 ms
15,616 KB
testcase_16 AC 270 ms
15,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

# 素数列挙
prime_generator = Prime::EratosthenesGenerator.new
@primes = []
begin ; @primes << prime_generator.next ; end while @primes[-1]<10000

@a = Array.new(10010)
@a[0] = true
@a[1] = true

# win?(num) numは先手必勝か後手必勝
def win?(n)
    @primes.each{|k|
        return false if n-k<0
        return true if !@a[n-k]
    }
    return false
end

2.upto(10000){|i|
    @a[i] = win?(i)
}

puts @a[gets.to_i] ? "Win" : "Lose"
0