結果

問題 No.7 プライムナンバーゲーム
ユーザー taisuketaisuke
提出日時 2023-02-20 11:38:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 518 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 8,616 KB
最終ジャッジ日時 2023-09-28 10:41:22
合計ジャッジ時間 4,722 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,876 KB
testcase_01 AC 14 ms
7,864 KB
testcase_02 AC 518 ms
8,576 KB
testcase_03 AC 44 ms
7,828 KB
testcase_04 AC 22 ms
7,896 KB
testcase_05 AC 23 ms
7,936 KB
testcase_06 AC 146 ms
7,680 KB
testcase_07 AC 110 ms
7,768 KB
testcase_08 AC 53 ms
7,684 KB
testcase_09 AC 243 ms
8,344 KB
testcase_10 AC 15 ms
7,944 KB
testcase_11 AC 113 ms
7,784 KB
testcase_12 AC 350 ms
8,488 KB
testcase_13 AC 358 ms
8,472 KB
testcase_14 AC 497 ms
8,584 KB
testcase_15 AC 506 ms
8,616 KB
testcase_16 AC 428 ms
8,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(n):
    sieve = [True] * ((n + 1) // 2)
    for i in range(1, (int(n ** 0.5) + 1) // 2):
        if sieve[i]:
            for j in range(i * 3 + 1, (n + 1) // 2, i * 2 + 1):
                sieve[j] = False
    res = [i * 2 + 1 for i, s in enumerate(sieve) if s]
    res[0] = 2
    return res


n = int(input())
prime = Eratosthenes(n)
dp = [False] * (n + 1)
dp[0] = dp[1] = True
for i in range(2, n+1):
    for x in prime:
        if i >= x and dp[i - x] == False:
            dp[i] = True
            break

ans = "Win" if dp[n] == True else "Lose"
print(ans)
0