結果

問題 No.7 プライムナンバーゲーム
ユーザー human_cipherhuman_cipher
提出日時 2021-06-16 02:13:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 842 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 8,796 KB
最終ジャッジ日時 2023-08-28 08:52:56
合計ジャッジ時間 8,007 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,468 KB
testcase_01 AC 18 ms
8,364 KB
testcase_02 AC 1,107 ms
8,720 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 32 ms
8,160 KB
testcase_06 AC 317 ms
8,492 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 465 ms
8,580 KB
testcase_10 WA -
testcase_11 AC 220 ms
8,340 KB
testcase_12 WA -
testcase_13 AC 778 ms
8,388 KB
testcase_14 AC 1,090 ms
8,796 KB
testcase_15 AC 961 ms
8,636 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt

def eratos(n):
    E = [True for _ in range(n+1)] #E[i]:iが素数かどうか
    E[0],E[1] = False,False
    for a in range(2,int(sqrt(n))+1):
        if E[a]:
            for i in range(2,n // a + 1):
                E[a * i] = False
    P = set()
    for a in range(n+1):
        if E[a]:
            P.add(a)
    return P

def solve(n):
    dp = [None for _ in range(n+1)] #dp[i]:iで先手番になったら先手が勝利かどうか
    dp[0],dp[1],dp[2],dp[3] = True,True,False,False
    P = eratos(n)
    for i in range(2,n+1):
        for p in P:
            if i+p <= n:
                if dp[i+p] == None:
                    dp[i+p] = not dp[i]
    return dp[n]

def main():
    n = int(input())
    if solve(n):
        print("Win")
    else:
        print("Lose")

if __name__ == "__main__":
    main()
0