結果

問題 No.7 プライムナンバーゲーム
ユーザー Ribura
提出日時 2020-05-01 00:10:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,136 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-10-01 16:33:55
合計ジャッジ時間 8,302 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import math


def eratosthenes(limit):
    A = [i for i in range(2, limit + 1)]
    P = []

    for i in range(limit):
        prime = min(A)

        if prime > math.sqrt(limit):
            break

        P.append(prime)
        for j in range(limit):
            if j >= len(A):
                break
            if A[j] % prime == 0:
                A.pop(j)
                continue

    for a in A:
        P.append(a)

    return P


n = int(readline())
prime_list = eratosthenes(n)
dp = [False] * (n + 1)
dp[0] = True
dp[1] = True
for i in range(2, n + 1):
    for prime in prime_list:
        if prime > i:
            break
        if not dp[i - prime]:
            dp[i] = True
if dp[-1]:
    print('Win')
else:
    print('Lose')
0