結果

問題 No.7 プライムナンバーゲーム
ユーザー human_cipherhuman_cipher
提出日時 2021-06-16 02:23:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,219 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-09 05:04:36
合計ジャッジ時間 8,796 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 1,219 ms
11,264 KB
testcase_03 AC 100 ms
11,008 KB
testcase_04 AC 47 ms
10,880 KB
testcase_05 AC 45 ms
10,752 KB
testcase_06 AC 351 ms
11,008 KB
testcase_07 AC 246 ms
10,880 KB
testcase_08 AC 126 ms
11,008 KB
testcase_09 AC 509 ms
11,136 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 251 ms
11,008 KB
testcase_12 AC 802 ms
11,136 KB
testcase_13 AC 836 ms
11,008 KB
testcase_14 AC 1,208 ms
11,136 KB
testcase_15 AC 1,031 ms
11,008 KB
testcase_16 AC 963 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

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 = [False for _ in range(n+1)] #dp[i]:iで先手番になったら先手が勝利かどうか
    dp[0],dp[1] = True,True
    P = eratos(n)
    for i in range(n+1):
        for p in P:
            if i-p >= 0:
                if not dp[i-p]:
                    dp[i] = True
    return dp[n]

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

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