結果

問題 No.7 プライムナンバーゲーム
ユーザー ronpooronpoo
提出日時 2023-08-22 11:34:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 76,696 KB
最終ジャッジ日時 2023-08-22 11:34:25
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,700 KB
testcase_01 AC 74 ms
71,604 KB
testcase_02 AC 92 ms
76,396 KB
testcase_03 AC 84 ms
76,548 KB
testcase_04 AC 78 ms
76,500 KB
testcase_05 AC 79 ms
76,696 KB
testcase_06 AC 86 ms
76,448 KB
testcase_07 AC 86 ms
76,536 KB
testcase_08 AC 85 ms
76,660 KB
testcase_09 AC 87 ms
76,608 KB
testcase_10 AC 72 ms
71,736 KB
testcase_11 AC 85 ms
76,432 KB
testcase_12 AC 90 ms
76,584 KB
testcase_13 AC 91 ms
76,500 KB
testcase_14 AC 94 ms
76,420 KB
testcase_15 AC 93 ms
76,416 KB
testcase_16 AC 92 ms
76,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

def prime(x):
    prime = [x if x%2==1 else 2 for x in range(x+1)]
    prime[0] = 1
    for i in range(3, int(x**0.5)+2, 2):
        if prime[i] != i:
            continue   
        for j in range(2*i, x+1, i):
            if prime[j] == j:
                prime[j] = i
    p = [i for i in range(2, x+1) if prime[i] == i]
    return p

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