結果

問題 No.7 プライムナンバーゲーム
ユーザー phantomilephantomile
提出日時 2015-12-22 04:10:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 1,117 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 76,348 KB
最終ジャッジ日時 2024-04-09 03:53:19
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,428 KB
testcase_01 AC 36 ms
53,924 KB
testcase_02 AC 89 ms
75,984 KB
testcase_03 AC 57 ms
71,148 KB
testcase_04 AC 52 ms
66,260 KB
testcase_05 AC 47 ms
63,376 KB
testcase_06 AC 69 ms
76,348 KB
testcase_07 AC 67 ms
76,124 KB
testcase_08 AC 61 ms
72,460 KB
testcase_09 AC 77 ms
76,320 KB
testcase_10 AC 35 ms
53,880 KB
testcase_11 AC 66 ms
76,084 KB
testcase_12 AC 82 ms
76,152 KB
testcase_13 AC 83 ms
75,976 KB
testcase_14 AC 91 ms
76,200 KB
testcase_15 AC 88 ms
75,988 KB
testcase_16 AC 88 ms
76,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
Yukicoder No.7
author: yamaton
date: 2015-12-18
"""

import math
import sys
import itertools

# sys.setrecursionlimit(100000)
#

def sieve(n):
    remaining = [True] * (n + 1)
    max_p = int(math.sqrt(n))
    for p in range(2, max_p + 1):
        if not remaining[p]:
            continue
        for q in range(p * p, n + 1, p):
            remaining[q] = False
    return [p for p in range(2, n + 1) if remaining[p]]


#
# @functools.lru_cache(maxsize=100000)
# def solve_old(n):
#     if n == 0 or n == 1:
#         return True
#     assert n >= 2
#     return any(not solve(n-i) for i in sieve(n))


def solve(n):
    primes = sieve(n)

    dp = [None] * (n + 1)
    dp[0] = True
    dp[1] = True
    for i in range(2, n+1):
        dp[i] = any(not dp[i-p] for p in
                    itertools.takewhile(lambda p: p <= i, primes))
    return dp[n]


def tf_to_wl(tf):
    return 'Win' if tf else "Lose"


def pp(*args, **kwargs):
    return print(*args, file=sys.stderr, **kwargs)


def main():
    n = int(input())
    result = tf_to_wl(solve(n))
    print(result)


if __name__ == '__main__':
    main()
0