結果

問題 No.7 プライムナンバーゲーム
ユーザー compass19compass19
提出日時 2017-01-02 23:37:14
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 784 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 9,096 KB
最終ジャッジ日時 2023-07-24 20:43:30
合計ジャッジ時間 6,349 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,964 KB
testcase_01 AC 16 ms
7,932 KB
testcase_02 AC 784 ms
9,096 KB
testcase_03 AC 65 ms
8,548 KB
testcase_04 AC 29 ms
8,432 KB
testcase_05 AC 29 ms
8,304 KB
testcase_06 AC 241 ms
8,528 KB
testcase_07 AC 165 ms
8,624 KB
testcase_08 AC 83 ms
8,528 KB
testcase_09 AC 353 ms
8,852 KB
testcase_10 AC 16 ms
7,872 KB
testcase_11 AC 170 ms
8,672 KB
testcase_12 AC 565 ms
8,892 KB
testcase_13 AC 604 ms
9,084 KB
testcase_14 AC 779 ms
9,076 KB
testcase_15 AC 738 ms
9,076 KB
testcase_16 AC 681 ms
8,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt, ceil

def era_prime(N):
    temp = [True]*(N+1)
    temp[0] = temp[1] = False
    for i in range(2, ceil(sqrt(N+1))):
        if temp[i]:
            temp[i+i::i] = [False]*(len(temp[i+i::i]))                            
    primes = [ n for n in range(N+1) if temp[n] ]
    return primes



n = int(input())
table = {0: True, 1: True}
primes = era_prime(n)

for i in range(2, n+1):
	# 自分以外の素数を引く
	tmp = [not table[i-x] for x in primes if x <= i]
	table[i] = True if any(tmp) else False

ans = 'Win' if table[n] else 'Lose'
print(ans)
0