結果

問題 No.7 プライムナンバーゲーム
ユーザー otsunekootsuneko
提出日時 2021-05-03 20:41:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 715 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 65,556 KB
最終ジャッジ日時 2024-04-09 05:03:38
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,672 KB
testcase_01 AC 35 ms
53,712 KB
testcase_02 AC 56 ms
64,420 KB
testcase_03 AC 46 ms
62,084 KB
testcase_04 AC 44 ms
60,444 KB
testcase_05 AC 44 ms
60,936 KB
testcase_06 AC 51 ms
64,496 KB
testcase_07 AC 51 ms
63,340 KB
testcase_08 AC 51 ms
62,864 KB
testcase_09 AC 52 ms
64,300 KB
testcase_10 AC 35 ms
52,816 KB
testcase_11 AC 52 ms
63,032 KB
testcase_12 AC 55 ms
64,444 KB
testcase_13 AC 55 ms
65,340 KB
testcase_14 AC 56 ms
63,700 KB
testcase_15 AC 56 ms
65,556 KB
testcase_16 AC 55 ms
63,740 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(2,N+1):
    for p in prime:
        if p > i:
            break
        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