結果

問題 No.7 プライムナンバーゲーム
ユーザー brthyyjpbrthyyjp
提出日時 2021-02-07 16:46:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 715 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 76,368 KB
最終ジャッジ日時 2024-04-09 05:02:59
合計ジャッジ時間 2,605 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
58,452 KB
testcase_01 AC 42 ms
59,120 KB
testcase_02 AC 154 ms
76,368 KB
testcase_03 AC 67 ms
75,904 KB
testcase_04 AC 55 ms
69,980 KB
testcase_05 AC 55 ms
68,956 KB
testcase_06 AC 86 ms
75,844 KB
testcase_07 AC 76 ms
75,876 KB
testcase_08 AC 68 ms
76,012 KB
testcase_09 AC 100 ms
76,092 KB
testcase_10 AC 41 ms
60,332 KB
testcase_11 AC 79 ms
76,276 KB
testcase_12 AC 127 ms
76,224 KB
testcase_13 AC 129 ms
75,908 KB
testcase_14 AC 150 ms
76,212 KB
testcase_15 AC 146 ms
76,040 KB
testcase_16 AC 138 ms
75,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

import math

def sieve(n):
    ass = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(math.sqrt(n))+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            ass.append(i)
    return(ass)

S = sieve(10**4+1)

dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
for i in range(2, n+1):
    res = []
    for s in S:
        if s <= i:
            res.append(dp[i-s])
        else:
            break
    if any(i == 0 for i in res):
        dp[i] = 1
    else:
        dp[i] = 0
if dp[n] == 1:
    print('Win')
else:
    print('Lose')
0