結果
| 問題 | 
                            No.7 プライムナンバーゲーム
                             | 
                    
| コンテスト | |
| ユーザー | 
                             80
                         | 
                    
| 提出日時 | 2018-09-05 23:54:36 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 680 bytes | 
| コンパイル時間 | 204 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 11,520 KB | 
| 最終ジャッジ日時 | 2024-11-15 18:29:39 | 
| 合計ジャッジ時間 | 1,809 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 2 WA * 3 RE * 12 | 
ソースコード
# -*- 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)
def grundy(x):
    #計算済みの場合
    if dp[x] == 0 :
        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):
        
        if isPrime[i] and x-i >= 2:
            lst.append(grundy(x-i))
        
    dp[x] = sum(lst)
    return dp[x]
res = grundy(N)
if res==0:
    print("Lose")
else:
    print("Win")
            
            
            
        
            
80