結果

問題 No.7 プライムナンバーゲーム
ユーザー 👑 rin204rin204
提出日時 2022-01-20 21:26:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 574 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 69,104 KB
最終ジャッジ日時 2024-04-09 05:06:32
合計ジャッジ時間 2,374 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
59,596 KB
testcase_01 AC 45 ms
59,544 KB
testcase_02 AC 142 ms
69,104 KB
testcase_03 AC 56 ms
63,908 KB
testcase_04 AC 53 ms
64,504 KB
testcase_05 AC 50 ms
63,704 KB
testcase_06 AC 77 ms
67,020 KB
testcase_07 AC 69 ms
65,572 KB
testcase_08 AC 57 ms
64,584 KB
testcase_09 AC 91 ms
66,488 KB
testcase_10 AC 41 ms
59,484 KB
testcase_11 AC 68 ms
65,844 KB
testcase_12 AC 116 ms
67,168 KB
testcase_13 AC 121 ms
67,096 KB
testcase_14 AC 142 ms
68,324 KB
testcase_15 AC 138 ms
67,700 KB
testcase_16 AC 132 ms
68,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 20000
isprime = [True] * N
isprime[0] = isprime[1] = False
for i in range(2, int(N ** 0.5 + 1)):
    if not isprime[i]:
        continue
    for j in range(i * i, N, i):
        isprime[j] = False

prime = []
for i in range(N):
    if isprime[i]:
        prime.append(i)

n = int(input()) 
grundy = [1] * (n + 1)
for i in range(2, n + 1):
    se = set()
    for p in prime:
        if p > i:
            break
        se.add(grundy[i - p])
    mex = 0
    while mex in se:
        mex += 1
    grundy[i] = mex

if grundy[n] == 0:
    print("Lose")
else:
    print("Win")
0