結果

問題 No.7 プライムナンバーゲーム
ユーザー compass19compass19
提出日時 2017-01-02 23:37:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,273 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-09 04:06:27
合計ジャッジ時間 9,712 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 1,255 ms
11,648 KB
testcase_03 AC 106 ms
11,264 KB
testcase_04 AC 50 ms
11,008 KB
testcase_05 AC 49 ms
11,136 KB
testcase_06 AC 388 ms
11,392 KB
testcase_07 AC 266 ms
11,136 KB
testcase_08 AC 134 ms
11,136 KB
testcase_09 AC 579 ms
11,520 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 266 ms
11,264 KB
testcase_12 AC 898 ms
11,520 KB
testcase_13 AC 960 ms
11,520 KB
testcase_14 AC 1,273 ms
11,648 KB
testcase_15 AC 1,181 ms
11,648 KB
testcase_16 AC 1,092 ms
11,648 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