結果

問題 No.7 プライムナンバーゲーム
ユーザー TomoyarnTomoyarn
提出日時 2023-01-04 09:28:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 780 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 76,636 KB
最終ジャッジ日時 2023-08-18 08:24:05
合計ジャッジ時間 3,284 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
75,996 KB
testcase_01 AC 74 ms
76,264 KB
testcase_02 AC 89 ms
76,432 KB
testcase_03 AC 82 ms
76,428 KB
testcase_04 AC 81 ms
76,296 KB
testcase_05 WA -
testcase_06 AC 89 ms
76,344 KB
testcase_07 AC 85 ms
76,168 KB
testcase_08 AC 81 ms
76,316 KB
testcase_09 WA -
testcase_10 AC 77 ms
76,176 KB
testcase_11 AC 84 ms
76,360 KB
testcase_12 AC 89 ms
76,500 KB
testcase_13 AC 89 ms
76,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 91 ms
76,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def sieve_of_eratosthenes(n):
    prime = [True for i in range(n+1)]
    prime[0] = False
    prime[1] = False

    sqrt_n = math.ceil(math.sqrt(n))
    for i in range(2, sqrt_n):
        if prime[i]:
            for j in range(2*i, n+1, i):
                prime[j] = False

    return prime
    

prime = sieve_of_eratosthenes(10000)

prm = []
for p in range(10001):
    if prime[p]:
        prm.append(p)

N = int(input())
dp = [0] * (N + 1)
for i in range(N + 1):
    dp[i] = True

if N <= 10:
    print("Win")
    exit()

for i in range(11, N + 1):
    winflag = False
    for p in prm:
        if p >= i:
            break
        elif dp[i - p] == False:
            winflag = True
            break
    dp[i] = winflag


print("Win" if dp[i] else "Lose")
    
0