結果

問題 No.7 プライムナンバーゲーム
コンテスト
ユーザー compass19
提出日時 2017-01-02 23:37:14
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 844 ms / 5,000 ms
+ 111µs
コード長 577 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 63 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2026-09-07 15:35:50
合計ジャッジ時間 7,440 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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