結果

問題 No.7 プライムナンバーゲーム
ユーザー FromBooskaFromBooska
提出日時 2023-03-02 12:35:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 81,608 KB
実行使用メモリ 64,272 KB
最終ジャッジ日時 2023-10-17 09:51:28
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
62,188 KB
testcase_01 AC 50 ms
62,188 KB
testcase_02 AC 62 ms
64,272 KB
testcase_03 AC 54 ms
64,272 KB
testcase_04 AC 53 ms
64,268 KB
testcase_05 AC 52 ms
64,268 KB
testcase_06 AC 56 ms
64,272 KB
testcase_07 AC 55 ms
64,272 KB
testcase_08 AC 54 ms
64,272 KB
testcase_09 AC 57 ms
64,272 KB
testcase_10 AC 48 ms
62,188 KB
testcase_11 AC 56 ms
64,272 KB
testcase_12 AC 59 ms
64,272 KB
testcase_13 AC 60 ms
64,272 KB
testcase_14 AC 61 ms
64,272 KB
testcase_15 AC 62 ms
64,272 KB
testcase_16 AC 61 ms
64,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 1次元dp, dp[i] 数iで手番の人は勝つ1、負ける0
# 昇順で埋めていく
# 素数は最初に列挙する
# 10**5だが素数の数は少ないので2重ループで間に合うのでは

mx = 10000
is_prime = [1]*(mx + 1)
is_prime[0] = 0  
is_prime[1] = 0
for p in range(2, mx + 1):
    if is_prime[p]:
        for q in range(2*p, mx + 1, p):
            is_prime[q] = 0

primes = []
for i in range(mx):
    if is_prime[i] == 1:
        primes.append(i)
        
N = int(input())
dp = [0]*(N+1)
for i in range(4, N+1):
    for p in primes:
        if i-p < 2:
            break
        if dp[i-p] == 0:
            dp[i] = 1
            break
#print(dp)
    
if dp[N] == 1:
    print('Win')
else:
    print('Lose')

0