結果

問題 No.7 プライムナンバーゲーム
ユーザー RiburaRibura
提出日時 2020-05-01 00:10:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,215 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-09 04:53:28
合計ジャッジ時間 9,224 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 1,215 ms
11,264 KB
testcase_03 AC 101 ms
10,880 KB
testcase_04 AC 50 ms
10,880 KB
testcase_05 AC 49 ms
10,880 KB
testcase_06 AC 384 ms
11,136 KB
testcase_07 AC 277 ms
11,008 KB
testcase_08 AC 144 ms
10,880 KB
testcase_09 AC 551 ms
11,008 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 243 ms
11,008 KB
testcase_12 AC 831 ms
11,136 KB
testcase_13 AC 897 ms
11,136 KB
testcase_14 AC 1,121 ms
11,392 KB
testcase_15 AC 1,076 ms
11,136 KB
testcase_16 AC 1,039 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

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