結果

問題 No.7 プライムナンバーゲーム
ユーザー 80
提出日時 2018-09-06 00:21:20
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 804 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-11-15 19:46:47
合計ジャッジ時間 1,575 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 2 RE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
N = int(input())
isPrime = [True] * (N + 1)

#エラトステネスの篩
for i in range(2,N + 1) :
    if isPrime[i]:
        for j in range(2 * i,N + 1,i):
            isPrime[j]=False
            
dp = [-1] * (N + 1)
#grundy数を求める
def grundy(x):
    #計算済みの場合
    if dp[x] != -1 :
        return dp[x]
    #2、または3を渡されたら負け
    if x == 2 or x == 3:
        dp[x] = 0
        return dp[x]
    
    #結果を収納するリスト
    lst = []
    for i in range(2,x+1):
        #iが素数で、かつ現在値からiを引いた数が2以上
        if isPrime[i] and x-i >= 4:
            lst.append(grundy(x-i))
        
    dp[x] = len(lst)
    return dp[x]

res = grundy(N)
if res!=0:
    print("Lose")
else:
    print("Win")



0