結果

問題 No.7 プライムナンバーゲーム
ユーザー otsunekootsuneko
提出日時 2021-05-03 15:54:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 677 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 76,840 KB
最終ジャッジ日時 2023-09-29 12:06:08
合計ジャッジ時間 2,737 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,068 KB
testcase_01 AC 69 ms
71,172 KB
testcase_02 AC 107 ms
76,380 KB
testcase_03 WA -
testcase_04 AC 78 ms
76,064 KB
testcase_05 WA -
testcase_06 AC 86 ms
76,300 KB
testcase_07 AC 83 ms
76,264 KB
testcase_08 AC 81 ms
76,388 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 83 ms
76,320 KB
testcase_12 AC 95 ms
76,296 KB
testcase_13 AC 94 ms
76,400 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 97 ms
76,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    table = [ i-1 for i in range(1, n+1) if is_prime[i-1]] # 素数のリスト
    return table

N = int(input())

prime = sieve(N)
win_lose = [0]*(N+1)
win_lose[0] = win_lose[1] = 1

for i in range(4,N+1):
    for p in prime:
        if win_lose[i-p] == 0:
            win_lose[i] = 1
            break
    else:
        win_lose[i] = 0

if win_lose[N]:
    print("Win")
else:
    print("Lose")
0