結果

問題 No.7 プライムナンバーゲーム
ユーザー compass19
提出日時 2017-01-02 23:37:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,353 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-10-01 15:51:53
合計ジャッジ時間 9,197 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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