結果

問題 No.7 プライムナンバーゲーム
ユーザー nebukuro09nebukuro09
提出日時 2016-09-30 10:35:47
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,726 ms / 5,000 ms
コード長 633 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,692 KB
最終ジャッジ日時 2024-04-09 04:03:40
合計ジャッジ時間 12,421 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,564 KB
testcase_01 AC 11 ms
6,692 KB
testcase_02 AC 1,722 ms
6,688 KB
testcase_03 AC 122 ms
6,692 KB
testcase_04 AC 41 ms
6,692 KB
testcase_05 AC 40 ms
6,692 KB
testcase_06 AC 513 ms
6,688 KB
testcase_07 AC 348 ms
6,688 KB
testcase_08 AC 163 ms
6,692 KB
testcase_09 AC 772 ms
6,692 KB
testcase_10 AC 10 ms
6,688 KB
testcase_11 AC 351 ms
6,688 KB
testcase_12 AC 1,241 ms
6,692 KB
testcase_13 AC 1,311 ms
6,688 KB
testcase_14 AC 1,726 ms
6,688 KB
testcase_15 AC 1,629 ms
6,692 KB
testcase_16 AC 1,505 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_table(n):
    list = [True for _ in xrange(n + 1)]
    i = 2
    while i * i <= n:
        if list[i]:
            j = i + i
            while j <= n:
                list[j] = False
                j += i
        i += 1

    table = [i for i in xrange(n + 1) if list[i] and i >= 2]
    return table

N = input()
table = prime_table(N)
grundy = [0 for _ in xrange(N+1)]
grundy[0] = 1
grundy[1] = 1
for i in xrange(3, N+1):
    a = []
    for p in table:
        if i-p < 0:
            break
        a.append(grundy[i-p])
    j = 0
    while j in a:
        j += 1
    grundy[i] = j

print 'Win' if grundy[N]>0 else 'Lose'
0