結果

問題 No.7 プライムナンバーゲーム
ユーザー maimai
提出日時 2017-02-04 11:16:58
言語 Ruby
(3.3.0)
結果
AC  
実行時間 336 ms / 5,000 ms
コード長 463 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-04-09 04:09:54
合計ジャッジ時間 6,853 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 330 ms
12,800 KB
testcase_01 AC 333 ms
12,800 KB
testcase_02 AC 336 ms
12,928 KB
testcase_03 AC 331 ms
12,672 KB
testcase_04 AC 331 ms
12,800 KB
testcase_05 AC 332 ms
12,544 KB
testcase_06 AC 330 ms
12,672 KB
testcase_07 AC 332 ms
12,544 KB
testcase_08 AC 330 ms
12,672 KB
testcase_09 AC 332 ms
12,672 KB
testcase_10 AC 326 ms
12,672 KB
testcase_11 AC 328 ms
12,672 KB
testcase_12 AC 331 ms
12,672 KB
testcase_13 AC 327 ms
12,672 KB
testcase_14 AC 332 ms
12,672 KB
testcase_15 AC 329 ms
12,544 KB
testcase_16 AC 328 ms
12,544 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