結果

問題 No.7 プライムナンバーゲーム
ユーザー shokayamorishokayamori
提出日時 2020-12-06 21:09:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 682 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,212 KB
最終ジャッジ日時 2024-09-17 13:13:27
合計ジャッジ時間 6,527 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

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 = [i - prime for prime in primes if prime<=i]
    dist_grundy = set([grundy[j] for j in residuals if j!=0 and j!=1])
    grundy[i] = min(set(range(i+1)) - set(dist_grundy))

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