結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
11,008 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 585 ms
10,880 KB
testcase_03 AC 65 ms
10,752 KB
testcase_04 AC 40 ms
11,008 KB
testcase_05 AC 39 ms
10,880 KB
testcase_06 AC 191 ms
11,136 KB
testcase_07 AC 141 ms
11,008 KB
testcase_08 AC 77 ms
10,752 KB
testcase_09 AC 276 ms
10,880 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 139 ms
11,008 KB
testcase_12 AC 424 ms
11,008 KB
testcase_13 AC 446 ms
11,008 KB
testcase_14 AC 584 ms
11,008 KB
testcase_15 AC 550 ms
11,008 KB
testcase_16 AC 513 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt

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 = [None] * (N+1)
    dp[0] = True
    dp[1] = True
    dp[2] = False
    dp[3] = False
    for i in range(4, N+1):
        if all([dp[i-j] for j in ps if j <= i]):
            dp[i] = False
        else:
            dp[i] = True

    print('Win' if dp[N] else 'Lose')


main()
0