結果

問題 No.7 プライムナンバーゲーム
ユーザー phantomile
提出日時 2015-12-22 03:47:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 812 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-09-18 18:31:36
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 RE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import functools
import math
import sys


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=8096)
def solve(n):
    if n == 0 or n == 1:
        return True
    assert n >= 2
    return any(not solve(n-i) for i in sieve(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