結果

問題 No.7 プライムナンバーゲーム
ユーザー shokayamorishokayamori
提出日時 2020-12-06 21:14:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,420 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-09 05:02:00
合計ジャッジ時間 10,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 1,420 ms
11,392 KB
testcase_03 AC 121 ms
10,880 KB
testcase_04 AC 52 ms
10,880 KB
testcase_05 AC 51 ms
10,752 KB
testcase_06 AC 439 ms
11,136 KB
testcase_07 AC 308 ms
11,008 KB
testcase_08 AC 158 ms
11,008 KB
testcase_09 AC 685 ms
11,136 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 298 ms
11,008 KB
testcase_12 AC 1,036 ms
11,136 KB
testcase_13 AC 1,143 ms
11,136 KB
testcase_14 AC 1,403 ms
11,264 KB
testcase_15 AC 1,322 ms
11,136 KB
testcase_16 AC 1,222 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

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 = [grundy[j] for j in residuals if j!=0 and j!=1]
    for k in range(i+1):
        if not k in dist_grundy:
            grundy[i] = k
            break

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