結果

問題 No.7 プライムナンバーゲーム
ユーザー maimai
提出日時 2017-02-04 11:16:36
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 460 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 11,324 KB
実行使用メモリ 15,584 KB
最終ジャッジ日時 2023-08-25 20:06:35
合計ジャッジ時間 3,225 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
15,476 KB
testcase_01 AC 93 ms
15,416 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 91 ms
15,504 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 91 ms
15,392 KB
testcase_10 AC 94 ms
15,512 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 93 ms
15,480 KB
testcase_15 AC 93 ms
15,540 KB
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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(20){|i|
    @a[i] = win?(i)
}

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