結果

問題 No.7 プライムナンバーゲーム
ユーザー human_cipherhuman_cipher
提出日時 2021-06-16 02:04:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 86,224 KB
実行使用メモリ 76,260 KB
最終ジャッジ日時 2023-08-28 08:41:27
合計ジャッジ時間 4,247 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,232 KB
testcase_01 AC 69 ms
71,336 KB
testcase_02 AC 285 ms
76,068 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 86 ms
76,016 KB
testcase_06 AC 142 ms
75,952 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 170 ms
75,604 KB
testcase_10 WA -
testcase_11 AC 122 ms
75,668 KB
testcase_12 WA -
testcase_13 AC 236 ms
75,668 KB
testcase_14 AC 281 ms
76,096 KB
testcase_15 AC 272 ms
75,612 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] = True,True,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