結果

問題 No.7 プライムナンバーゲーム
ユーザー KudeKude
提出日時 2020-09-03 07:36:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 431 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 63,864 KB
最終ジャッジ日時 2024-04-09 04:58:53
合計ジャッジ時間 1,883 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,132 KB
testcase_01 AC 37 ms
52,480 KB
testcase_02 AC 57 ms
62,648 KB
testcase_03 AC 48 ms
61,796 KB
testcase_04 AC 44 ms
59,484 KB
testcase_05 AC 45 ms
60,008 KB
testcase_06 AC 52 ms
63,732 KB
testcase_07 AC 49 ms
62,324 KB
testcase_08 AC 49 ms
62,952 KB
testcase_09 AC 52 ms
62,420 KB
testcase_10 AC 37 ms
53,228 KB
testcase_11 AC 49 ms
63,168 KB
testcase_12 AC 55 ms
62,276 KB
testcase_13 AC 55 ms
62,680 KB
testcase_14 AC 58 ms
63,864 KB
testcase_15 AC 57 ms
62,404 KB
testcase_16 AC 56 ms
62,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

sieve = [True] * (n + 1)
primes = []
for p in range(2, n + 1):
    if sieve[p]:
        primes.append(p)
        for i in range(p * p, n + 1, p):
            sieve[i] = False

dp = [True] * (n + 1)
for i in range(2, n + 1):
    ok = False
    for p in primes:
        if p > i:
            break
        if dp[i-p] == False:
            ok = True
            break
    dp[i] = ok
print('Win' if dp[n] else 'Lose')
0