結果

問題 No.7 プライムナンバーゲーム
ユーザー daleksprinterdaleksprinter
提出日時 2018-08-13 04:00:17
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 7,124 KB
実行使用メモリ 6,872 KB
最終ジャッジ日時 2023-10-24 16:27:24
合計ジャッジ時間 6,939 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,684 KB
testcase_01 AC 12 ms
6,684 KB
testcase_02 AC 819 ms
6,872 KB
testcase_03 AC 63 ms
6,720 KB
testcase_04 AC 24 ms
6,696 KB
testcase_05 AC 24 ms
6,696 KB
testcase_06 AC 248 ms
6,780 KB
testcase_07 AC 170 ms
6,756 KB
testcase_08 AC 81 ms
6,728 KB
testcase_09 AC 371 ms
6,804 KB
testcase_10 AC 11 ms
6,684 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 818 ms
6,872 KB
testcase_15 AC 777 ms
6,864 KB
testcase_16 AC 719 ms
6,860 KB
権限があれば一括ダウンロードができます

ソースコード

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