結果

問題 No.7 プライムナンバーゲーム
ユーザー TawaraTawara
提出日時 2016-01-13 11:19:33
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 501 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 7,112 KB
実行使用メモリ 7,356 KB
最終ジャッジ日時 2023-10-19 22:57:55
合計ジャッジ時間 1,440 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,576 KB
testcase_01 AC 11 ms
6,576 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 36 ms
6,828 KB
testcase_05 AC 35 ms
6,828 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 11 ms
6,576 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

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