結果

問題 No.7 プライムナンバーゲーム
ユーザー ssmkzkssmkzk
提出日時 2018-10-25 16:51:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 448 ms / 5,000 ms
コード長 680 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-09 04:33:31
合計ジャッジ時間 4,360 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 448 ms
11,136 KB
testcase_03 AC 56 ms
11,008 KB
testcase_04 AC 36 ms
10,880 KB
testcase_05 AC 35 ms
10,880 KB
testcase_06 AC 153 ms
11,008 KB
testcase_07 AC 109 ms
11,008 KB
testcase_08 AC 69 ms
11,008 KB
testcase_09 AC 211 ms
11,136 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 113 ms
10,880 KB
testcase_12 AC 331 ms
11,264 KB
testcase_13 AC 330 ms
11,264 KB
testcase_14 AC 423 ms
11,264 KB
testcase_15 AC 434 ms
11,264 KB
testcase_16 AC 377 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def SoE(x):
    if x < 2:
        return []
    
    l = [i for i in range(x + 1)]
    l[1] = 0
    
    for i in l:
        if i > math.sqrt(x):
            break
        if i == 0:
            continue
        for j in range(2 * i , x + 1, i):
            l[j] = 0
    
    return [i for i in l if i != 0]

N = int(input())
l_prime = SoE(N)

dp = [0 for i in range(N + 1)]
dp[0] = 1
dp[1] = 1

for i in range(2, N + 1):
    for prime in l_prime:
        if i < prime:
            break
        if dp[i - prime] == 0:
            dp[i] = 1
            break
    else:
        dp[-1] = 0



# print(dp)

if dp[-1]:
    print("Win")
else:
    print("Lose")


        
0