結果

問題 No.7 プライムナンバーゲーム
ユーザー kutsutamakutsutama
提出日時 2018-12-16 02:06:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 315 ms / 5,000 ms
コード長 767 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 04:34:26
合計ジャッジ時間 3,239 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 290 ms
11,136 KB
testcase_03 AC 47 ms
10,880 KB
testcase_04 AC 35 ms
10,880 KB
testcase_05 AC 34 ms
10,752 KB
testcase_06 AC 100 ms
11,008 KB
testcase_07 AC 80 ms
11,008 KB
testcase_08 AC 53 ms
11,136 KB
testcase_09 AC 140 ms
11,136 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 79 ms
10,880 KB
testcase_12 AC 219 ms
11,136 KB
testcase_13 AC 220 ms
11,136 KB
testcase_14 AC 315 ms
11,136 KB
testcase_15 AC 278 ms
11,008 KB
testcase_16 AC 285 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def isprime(x, prime):
    res = True
    sq = math.sqrt(x)
    for i in range(2, len(prime)):
        if prime[i] > sq or prime[i] == 0:
            break
        if x % prime[i] == 0:
            res = False
            break
    return res

n = int(input())

prime = [0] * n
prime[0] = 2
prime[1] = 3
pnum = 2
for x in range(6, n + 1, 6):
    x1 = x - 1
    x2 = x + 1
    if isprime(x1, prime):
        prime[pnum] = x1
        pnum += 1
    if isprime(x2, prime):
        prime[pnum] = x2
        pnum += 1

win = [False] * (2 * n + 1)
los = 2
for i in range(2, n):
    if win[i]:
        continue
    los = i
    for p in prime:
        if p == 0:
            break
        win[p + los] = True

if win[n]:
    print('Win')
else:
    print('Lose')

0