結果

問題 No.7 プライムナンバーゲーム
ユーザー maatanbetamaatanbeta
提出日時 2017-05-12 17:28:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,185 ms / 5,000 ms
コード長 815 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-09 04:20:53
合計ジャッジ時間 15,257 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 2,185 ms
11,392 KB
testcase_03 AC 129 ms
11,008 KB
testcase_04 AC 49 ms
10,752 KB
testcase_05 AC 49 ms
10,752 KB
testcase_06 AC 581 ms
11,136 KB
testcase_07 AC 372 ms
11,136 KB
testcase_08 AC 168 ms
10,880 KB
testcase_09 AC 898 ms
11,008 KB
testcase_10 AC 29 ms
11,008 KB
testcase_11 AC 380 ms
11,136 KB
testcase_12 AC 1,539 ms
11,136 KB
testcase_13 AC 1,634 ms
11,136 KB
testcase_14 AC 2,176 ms
11,392 KB
testcase_15 AC 2,074 ms
11,392 KB
testcase_16 AC 1,886 ms
11,264 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