結果

問題 No.7 プライムナンバーゲーム
ユーザー shokayamorishokayamori
提出日時 2020-12-06 21:00:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 712 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 12,092 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2023-10-17 15:30:29
合計ジャッジ時間 6,891 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve_of_eratosthenes(N):
    thresh = int(N ** 0.5)
    nums = list(range(2, N+1))
    for i in range(N):
        prime = nums[i]
        nums = [num for num in nums
            if (num<=prime) or (num%prime!=0)]
        if prime > thresh:
            break
    return nums

N = int(input())
primes = sieve_of_eratosthenes(N)

grundy = [None] * (N+1)
grundy[0] = 0
grundy[1] = 0
grundy[2] = 0
grundy[3] = 0
for i in range(4, N+1):
    residuals = list(set([i - prime for prime in primes if prime<=i]) - set([0,1]))
    dist_grundy = set([grundy[j] for j in residuals])
    print(dist_grundy)
    grundy[i] = min(set(range(i+1)) - set(dist_grundy))

if grundy[-1]==0:
    print('Lose')
else:
    print('Win')
0