結果

問題 No.7 プライムナンバーゲーム
ユーザー DialBirdDialBird
提出日時 2019-07-23 08:39:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 807 ms / 5,000 ms
コード長 738 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-09 04:41:12
合計ジャッジ時間 6,431 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 807 ms
11,648 KB
testcase_03 AC 80 ms
11,264 KB
testcase_04 AC 43 ms
11,008 KB
testcase_05 AC 43 ms
11,008 KB
testcase_06 AC 258 ms
11,136 KB
testcase_07 AC 182 ms
11,008 KB
testcase_08 AC 98 ms
11,136 KB
testcase_09 AC 373 ms
11,648 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 185 ms
11,008 KB
testcase_12 AC 583 ms
11,776 KB
testcase_13 AC 619 ms
11,776 KB
testcase_14 AC 798 ms
11,776 KB
testcase_15 AC 762 ms
11,648 KB
testcase_16 AC 703 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from itertools import takewhile

def primes(n):
    if n < 1:
        return []

    is_prime = [True] * (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
    return [i for i in range(2, n+1) if is_prime[i]]

def main():
    """ main """
    N = int(input())

    if N < 4:
        print('Lose')
        return

    ps = primes(N)
    dp = set([0, 1])
    for i in range(4, N+1):
        for j in list(takewhile(lambda x: x <= i, ps)):
            if i - j not in dp:
                dp.add(i)
                break

    print('Win' if N in dp else 'Lose')


main()
0