結果

問題 No.7 プライムナンバーゲーム
ユーザー daleksprinterdaleksprinter
提出日時 2018-08-13 04:10:39
言語 Python2
(2.7.18)
結果
AC  
実行時間 339 ms / 5,000 ms
コード長 544 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-04-09 04:31:25
合計ジャッジ時間 5,206 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
6,912 KB
testcase_01 AC 20 ms
6,912 KB
testcase_02 AC 332 ms
7,040 KB
testcase_03 AC 256 ms
6,912 KB
testcase_04 AC 163 ms
7,040 KB
testcase_05 AC 161 ms
7,040 KB
testcase_06 AC 339 ms
7,040 KB
testcase_07 AC 331 ms
6,944 KB
testcase_08 AC 282 ms
6,912 KB
testcase_09 AC 338 ms
7,040 KB
testcase_10 AC 19 ms
7,040 KB
testcase_11 AC 333 ms
7,040 KB
testcase_12 AC 334 ms
6,912 KB
testcase_13 AC 333 ms
7,040 KB
testcase_14 AC 331 ms
7,040 KB
testcase_15 AC 331 ms
7,040 KB
testcase_16 AC 332 ms
6,948 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+2)

game = ['L' for i in range(10**4+10)]

game[2] = 'L'
game[3] = 'L'

i = 2
while i < len(game):
	if game[i] == 'L':
		t = 0
		while t < len(primes) and i + primes[t] < len(game) :
			game[i + primes[t]] = 'W'
			t += 1

	i += 1

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