結果

問題 No.7 プライムナンバーゲーム
ユーザー (ΦωΦ)(ΦωΦ)
提出日時 2015-04-15 21:18:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 339 ms / 5,000 ms
コード長 516 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 7,080 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:44:39
合計ジャッジ時間 3,274 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,816 KB
testcase_01 AC 12 ms
6,948 KB
testcase_02 AC 339 ms
6,948 KB
testcase_03 AC 33 ms
6,948 KB
testcase_04 AC 17 ms
6,944 KB
testcase_05 AC 17 ms
6,948 KB
testcase_06 AC 108 ms
6,948 KB
testcase_07 AC 77 ms
6,948 KB
testcase_08 AC 40 ms
6,948 KB
testcase_09 AC 159 ms
6,944 KB
testcase_10 AC 12 ms
6,948 KB
testcase_11 AC 77 ms
6,944 KB
testcase_12 AC 245 ms
6,944 KB
testcase_13 AC 260 ms
6,948 KB
testcase_14 AC 338 ms
6,948 KB
testcase_15 AC 322 ms
6,948 KB
testcase_16 AC 295 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python

def sieve(n):
    is_prime = [0, 0] + [1] * (n-1)
    sq = int(n ** .5)
    for i in xrange(2, sq+1):
        if is_prime[i]:
            for j in xrange(i*i, n+1, i):
                is_prime[j] = 0
    return [i for i, p in enumerate(is_prime) if p]

N = int(raw_input())
primes = sieve(N)
win = [1] * 2 + [0] * N
for i in xrange(2, N+1):
    for p in primes:
        if p > i:
            break
        if not win[i-p]:
            win[i] = 1
            break
print 'Win' if win[N] else 'Lose'
0