結果

問題 No.7 プライムナンバーゲーム
ユーザー gigurururugigurururu
提出日時 2014-11-05 20:34:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 306 ms / 5,000 ms
コード長 726 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-04-09 03:40:07
合計ジャッジ時間 3,067 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,816 KB
testcase_01 AC 13 ms
6,948 KB
testcase_02 AC 306 ms
6,948 KB
testcase_03 AC 31 ms
6,944 KB
testcase_04 AC 18 ms
6,948 KB
testcase_05 AC 17 ms
6,948 KB
testcase_06 AC 97 ms
6,948 KB
testcase_07 AC 70 ms
6,948 KB
testcase_08 AC 38 ms
6,944 KB
testcase_09 AC 142 ms
6,944 KB
testcase_10 AC 12 ms
6,944 KB
testcase_11 AC 70 ms
6,944 KB
testcase_12 AC 222 ms
6,944 KB
testcase_13 AC 236 ms
6,948 KB
testcase_14 AC 305 ms
7,040 KB
testcase_15 AC 290 ms
7,040 KB
testcase_16 AC 269 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import ifilter, islice
def gen_odd():
    n = 3
    while True:
        yield n
        n += 2

def iprimes():
    yield 2
    g = gen_odd()
    while True:
        prime = g.next()
        s_prime = prime * prime
        ps = []
        while s_prime != prime:
            yield prime
            ps.append(prime)
            prime = g.next()
        pred = lambda x, ps = ps: all(x % p for p in ps)
        g = ifilter(pred, g)

n=input()

primes=[]
for i in iprimes():
    if i > n: break
    primes.append(i)

w=[False]*(n+1)
for c in range(2,n+1):
    if w[c]==False:
        for i in [j for j in primes if j+c<=n]:
            w[i+c]=True

print "Win" if w[n] else "Lose"
0