結果

問題 No.7 プライムナンバーゲーム
ユーザー taisuke
提出日時 2023-02-20 11:38:44
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 562 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-21 05:23:44
合計ジャッジ時間 4,803 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(n):
    sieve = [True] * ((n + 1) // 2)
    for i in range(1, (int(n ** 0.5) + 1) // 2):
        if sieve[i]:
            for j in range(i * 3 + 1, (n + 1) // 2, i * 2 + 1):
                sieve[j] = False
    res = [i * 2 + 1 for i, s in enumerate(sieve) if s]
    res[0] = 2
    return res


n = int(input())
prime = Eratosthenes(n)
dp = [False] * (n + 1)
dp[0] = dp[1] = True
for i in range(2, n+1):
    for x in prime:
        if i >= x and dp[i - x] == False:
            dp[i] = True
            break

ans = "Win" if dp[n] == True else "Lose"
print(ans)
0