結果

問題 No.7 プライムナンバーゲーム
ユーザー H3PO4H3PO4
提出日時 2020-04-17 11:38:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,493 ms / 5,000 ms
コード長 618 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 04:52:25
合計ジャッジ時間 11,381 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 1,493 ms
10,880 KB
testcase_03 AC 117 ms
10,752 KB
testcase_04 AC 53 ms
10,752 KB
testcase_05 AC 51 ms
10,752 KB
testcase_06 AC 456 ms
10,752 KB
testcase_07 AC 307 ms
10,752 KB
testcase_08 AC 159 ms
11,008 KB
testcase_09 AC 680 ms
10,752 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 314 ms
10,752 KB
testcase_12 AC 1,063 ms
10,752 KB
testcase_13 AC 1,135 ms
10,880 KB
testcase_14 AC 1,492 ms
11,008 KB
testcase_15 AC 1,446 ms
11,008 KB
testcase_16 AC 1,336 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return (i for i in range(n + 1) if is_prime[i])


P = tuple(primes(N))
table = [True] * (N + 1)
table[2], table[3] = False, False
for i in range(4, N + 1):
    tmp = False
    for p in P:
        if i - p < 0:
            break
        if not table[i - p]:
            tmp = True
    table[i] = tmp
print("Win" if table[N] else "Lose")
0