結果

問題 No.7 プライムナンバーゲーム
ユーザー kichirb3
提出日時 2018-03-07 23:20:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 278 ms / 5,000 ms
コード長 1,090 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-10-01 16:09:04
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.7 プライムナンバーゲーム
https://yukicoder.me/problems/no/7

"""
import sys
from sys import stdin
input = stdin.readline


def create_prime_list(limit):
    """
    エラトステネスの篩でlimitまでの素数リストを求める
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    nums = [x for x in range(2, limit+1)]
    while nums[0]<=x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x%current_prime != 0]
    primes.extend(nums)
    return primes


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

    primes = create_prime_list(N)

    lut = [False] * (N+1)       #  先攻が勝てるかどうかの判定表
    for i in range(4, N+1):
        for p in primes:
            if 2 <= i-p and lut[i-p] is False:
                lut[i] = True
                break

    if lut[N]:
        print('Win')
    else:
        print('Lose')


if __name__ == '__main__':
    main(sys.argv[1:])
0