結果

問題 No.7 プライムナンバーゲーム
ユーザー maatanbetamaatanbeta
提出日時 2017-05-12 17:28:30
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,723 ms / 5,000 ms
コード長 815 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 8,824 KB
最終ジャッジ日時 2023-07-24 20:58:22
合計ジャッジ時間 12,247 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,940 KB
testcase_01 AC 16 ms
8,036 KB
testcase_02 AC 1,723 ms
8,568 KB
testcase_03 AC 97 ms
7,920 KB
testcase_04 AC 33 ms
7,884 KB
testcase_05 AC 32 ms
7,944 KB
testcase_06 AC 448 ms
8,476 KB
testcase_07 AC 293 ms
8,500 KB
testcase_08 AC 130 ms
8,032 KB
testcase_09 AC 698 ms
8,608 KB
testcase_10 AC 16 ms
7,940 KB
testcase_11 AC 295 ms
8,596 KB
testcase_12 AC 1,201 ms
8,616 KB
testcase_13 AC 1,277 ms
8,812 KB
testcase_14 AC 1,702 ms
8,692 KB
testcase_15 AC 1,627 ms
8,824 KB
testcase_16 AC 1,477 ms
8,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N = int(input())


def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]


kachi = [False] * (N + 1)
kachi[0] = True
kachi[1] = True
for k in range(N):
    if k == 0 or k == 1 or kachi[k]:
        continue
    for i in make_prime_list_2(N):
        if k + i <= N:
            kachi[k + i] = True

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