結果

問題 No.7 プライムナンバーゲーム
ユーザー nagitaosunagitaosu
提出日時 2020-03-13 09:53:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 736 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 62,984 KB
最終ジャッジ日時 2024-04-09 04:50:49
合計ジャッジ時間 2,035 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
61,232 KB
testcase_01 AC 56 ms
62,092 KB
testcase_02 AC 55 ms
62,252 KB
testcase_03 AC 56 ms
62,128 KB
testcase_04 AC 55 ms
61,024 KB
testcase_05 AC 56 ms
62,416 KB
testcase_06 AC 57 ms
62,324 KB
testcase_07 AC 55 ms
62,024 KB
testcase_08 AC 58 ms
62,620 KB
testcase_09 AC 56 ms
62,984 KB
testcase_10 AC 57 ms
61,080 KB
testcase_11 AC 56 ms
61,508 KB
testcase_12 AC 54 ms
62,016 KB
testcase_13 AC 56 ms
62,468 KB
testcase_14 AC 55 ms
62,148 KB
testcase_15 AC 57 ms
61,416 KB
testcase_16 AC 55 ms
61,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

# O(nloglogn)
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]]

max_n = 10**4 + 10
n = int(input())
p = primes(max_n)

dp = [0] * (10**4 + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, 10**4 + 1):
    index = 0
    prime = p[index]
    while prime <= i:
        if not dp[i - prime]:
            dp[i] = 1
            break
        index += 1
        prime = p[index]

if dp[n]:
    print("Win")
else:
    print("Lose")
0