結果

問題 No.7 プライムナンバーゲーム
ユーザー TomoyarnTomoyarn
提出日時 2023-01-04 09:37:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 875 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 76,540 KB
最終ジャッジ日時 2023-08-18 08:29:35
合計ジャッジ時間 2,947 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,396 KB
testcase_01 AC 77 ms
76,228 KB
testcase_02 AC 118 ms
76,436 KB
testcase_03 AC 86 ms
76,424 KB
testcase_04 AC 83 ms
76,492 KB
testcase_05 AC 83 ms
76,488 KB
testcase_06 AC 93 ms
76,540 KB
testcase_07 AC 88 ms
76,272 KB
testcase_08 AC 87 ms
76,460 KB
testcase_09 AC 98 ms
76,268 KB
testcase_10 AC 76 ms
76,240 KB
testcase_11 AC 90 ms
76,460 KB
testcase_12 AC 109 ms
76,268 KB
testcase_13 AC 111 ms
76,380 KB
testcase_14 AC 118 ms
76,532 KB
testcase_15 AC 118 ms
76,344 KB
testcase_16 AC 112 ms
76,376 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

dp[2] = False
dp[3] = False



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
#            if i == N:
#                print(i, p, dp[i - p])
            break
    dp[i] = winflag


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