結果

問題 No.7 プライムナンバーゲーム
ユーザー nuwasogi
提出日時 2015-11-24 16:16:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,386 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-10-01 15:38:04
合計ジャッジ時間 10,222 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False
# return prime list where less than n
def sieve(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if s[i] and i > 1]

if __name__ == "__main__":
    N = int(input())
    if N <= 3:
        print("Lose")
    else:
        slist = sieve(N - 1)
        WLList = [False] * (N+1)
        checkList = []
        for x in range(4, N+1):
            if x-2 in slist:
                checkList.append(x-2)
            checkList2 = list(map(lambda p : x-p, checkList))
            for y in checkList2:
                if WLList[y] == False:
                    WLList[x] = True
        if WLList[N]:
            print("Win")
        else:
            print("Lose")
0