結果

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

ソースコード

diff #

N = int(input())


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return (i for i in range(n + 1) if is_prime[i])


P = tuple(primes(N))
table = [True] * (N + 1)
table[2], table[3] = False, False
for i in range(4, N + 1):
    tmp = False
    for p in P:
        if i - p < 0:
            break
        if not table[i - p]:
            tmp = True
    table[i] = tmp
print("Win" if table[N] else "Lose")
0