結果

問題 No.7 プライムナンバーゲーム
ユーザー ntuda
提出日時 2022-10-31 00:05:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 331 ms / 5,000 ms
コード長 730 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 88,448 KB
最終ジャッジ日時 2024-07-07 14:47:09
合計ジャッジ時間 3,723 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from functools import lru_cache
sys.setrecursionlimit(10000)

def seachPrimeNum(N):
    max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

N = int(input())
PL = seachPrimeNum(N)

@lru_cache(maxsize=10000)
def dfs(x):
    for p in PL:
        if x < p:
            break
        if x - p == 0 or x - p == 1:
            return True
        #print(x,x-p,dfs(x-p))
        if dfs(x-p) == True:
            return False
    return True

if dfs(N):
    print("Lose")
else:
    print("Win")
0