結果

問題 No.7 プライムナンバーゲーム
ユーザー nuwasoginuwasogi
提出日時 2015-11-24 16:16:36
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,219 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,748 KB
最終ジャッジ日時 2023-07-24 20:27:36
合計ジャッジ時間 9,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,848 KB
testcase_01 AC 15 ms
7,796 KB
testcase_02 AC 1,171 ms
8,628 KB
testcase_03 AC 87 ms
8,404 KB
testcase_04 AC 32 ms
7,776 KB
testcase_05 AC 32 ms
7,816 KB
testcase_06 AC 350 ms
8,588 KB
testcase_07 AC 247 ms
8,400 KB
testcase_08 AC 114 ms
8,552 KB
testcase_09 AC 527 ms
8,424 KB
testcase_10 AC 16 ms
7,740 KB
testcase_11 AC 255 ms
8,464 KB
testcase_12 AC 916 ms
8,748 KB
testcase_13 AC 910 ms
8,708 KB
testcase_14 AC 1,219 ms
8,728 KB
testcase_15 AC 1,124 ms
8,692 KB
testcase_16 AC 1,081 ms
8,712 KB
権限があれば一括ダウンロードができます

ソースコード

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