結果

問題 No.7 プライムナンバーゲーム
ユーザー Tawara
提出日時 2016-01-13 11:19:33
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 501 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-09-19 18:55:38
合計ジャッジ時間 1,319 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 RE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def sieve (n):
	check = [True]*(n+1)
	check[0] = check[1] = False
	for d in xrange(2,int(math.sqrt(n))+1):
		if not check[d]: continue
		for comp in xrange(d*2,n+1,d):
			check[comp] = False
	return [i for i in xrange(2,n+1) if check[i]]
N = input(); memo = [None]*(N+1); prime = sieve(N)
memo[0] = memo[1] = True
def dfs(n):
	if memo[n] is None:
		tmp = False
		for p in prime:
			if p > n: continue
			tmp |= not dfs(n-p)
		memo[n] = tmp
	return memo[n]
print "Win" if dfs(N) else "Lose"
0