結果

問題 No.7 プライムナンバーゲーム
ユーザー rlangevinrlangevin
提出日時 2023-01-08 02:17:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 588 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 76,556 KB
最終ジャッジ日時 2023-08-21 15:06:24
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,752 KB
testcase_01 AC 79 ms
75,744 KB
testcase_02 AC 99 ms
76,284 KB
testcase_03 AC 82 ms
76,340 KB
testcase_04 AC 82 ms
76,480 KB
testcase_05 AC 80 ms
76,288 KB
testcase_06 AC 86 ms
76,180 KB
testcase_07 AC 85 ms
76,424 KB
testcase_08 AC 82 ms
76,336 KB
testcase_09 AC 90 ms
76,172 KB
testcase_10 AC 78 ms
75,776 KB
testcase_11 AC 85 ms
76,556 KB
testcase_12 AC 92 ms
76,220 KB
testcase_13 AC 93 ms
76,432 KB
testcase_14 AC 97 ms
76,272 KB
testcase_15 AC 97 ms
76,320 KB
testcase_16 AC 94 ms
76,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *

def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return sorted(list(S))

S = Sieve(10000)

N = int(input())
dp = [0] * (N + 1)
dp[0] = dp[1] = 1
for i in range(2, N + 1):
    flag = 1
    for s in S:
        if i - s < 0:
            break
        flag &= dp[i - s]
    if flag == 0:
        dp[i] = 1
        
print("Win") if dp[N] else print("Lose")
0