結果

問題 No.7 プライムナンバーゲーム
ユーザー mationaruzoumationaruzou
提出日時 2020-06-19 14:13:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 9,448 KB
最終ジャッジ日時 2023-09-16 12:47:52
合計ジャッジ時間 5,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,812 KB
testcase_01 AC 16 ms
7,924 KB
testcase_02 AC 607 ms
9,376 KB
testcase_03 AC 49 ms
8,408 KB
testcase_04 AC 23 ms
8,308 KB
testcase_05 WA -
testcase_06 AC 172 ms
8,720 KB
testcase_07 AC 114 ms
8,644 KB
testcase_08 AC 59 ms
8,484 KB
testcase_09 WA -
testcase_10 AC 15 ms
7,808 KB
testcase_11 AC 120 ms
8,684 KB
testcase_12 AC 370 ms
9,220 KB
testcase_13 AC 461 ms
9,264 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 519 ms
9,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
n = int(input())

pflag = [True]*(n+1)
primes = []
for i in range(2, n):
    if pflag[i]:
        primes.append(i)
        num = 2
        while i*num <= n:
            pflag[i*num] = False
            num += 1
sys.setrecursionlimit(10000)
win = [-1]*(n+1)


def ok(n):
    if n == 2 or n == 3:
        win[n] = 0
        return win[n]
    if win[n] != -1:
        return win[n]
    for prime in primes:
        if n-prime < 2:
            win[n] = 0
            return win[n]
        s = ok(n-prime)
        if s == 0:
            win[n] = 1
            return win[n]


if ok(n) == 0:
    print("Lose")
else:
    print("Win")
0