結果

問題 No.7 プライムナンバーゲーム
ユーザー togatoga
提出日時 2015-08-25 10:14:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 649 ms / 5,000 ms
コード長 710 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-10-01 15:36:18
合計ジャッジ時間 5,315 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import time
sys.setrecursionlimit(1 << 30)
N = eval(input())
dp = [-1 for i in range(10010)]
prime = [True for i in range(10010)]
p = []
def sieve():
    prime[0] = False
    prime[1] = False
    for i in range(2, 10001):
        if (prime[i]):
            p.append(i)
            for j in range(i * i, 10001, i):
                prime[j] = False


def memo(pos):
    if (pos == 0 or pos == 1):
        return True
    win = False
    if (dp[pos] >= 0):
        return dp[pos]
    for i in p:
        if (i > pos):
            break
        win |= not memo(pos - i)
        if (win):
            break
    dp[pos] = win
    return win

sieve()
if (memo(N)):
    print("Win")
else:
    print("Lose")
0