結果

問題 No.7 プライムナンバーゲーム
ユーザー daleksprinter
提出日時 2018-08-13 04:00:17
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-24 07:42:31
合計ジャッジ時間 6,569 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

def mark(s, x):
    for i in xrange(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in xrange(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in xrange(0,n) if s[i] and i > 1]

n = int(input())

primes =  sieve(n)

game = ['W','W','L','L']

i = 4
while i < n+1:
	j = 0
	flag = 'L'
	while primes[j] <= i :
		if game[i - primes[j]] == 'L':
			flag = 'W'
			break
		
		if j+1 < len(primes)-1 :
			j += 1
		else :
			break


	game.append(flag)
	i += 1

print 'Win' if game[n] == 'W' else 'Lose'
0