結果

問題 No.7 プライムナンバーゲーム
ユーザー netyo715netyo715
提出日時 2021-06-21 11:20:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 465 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2023-09-05 01:49:48
合計ジャッジ時間 1,718 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,936 KB
testcase_01 AC 16 ms
7,876 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 81 ms
8,516 KB
testcase_05 AC 78 ms
8,460 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 16 ms
7,948 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

hurui = set(range(2, N+1))
for i in range(2, N+1):
    for j in range(i*2, N+1, i):
        hurui.discard(j)

dp = [-1]*(N+10)
dp[0] = 0
dp[1] = 0
def grundy(x):
    if dp[x] != -1:
        return dp[x]
    s = set()
    for i in range(2, x+1):
        if i in hurui:
            s.add(grundy(x-i))
    for i in range(x+1):
        if i not in s:
            dp[x] = i
            return i

if grundy(N)&1:
    print("Lose")
else:
    print("Win")
0