結果

問題 No.7 プライムナンバーゲーム
ユーザー kutsutamakutsutama
提出日時 2018-12-15 18:37:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 693 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,816 KB
実行使用メモリ 10,224 KB
最終ジャッジ日時 2023-10-25 21:55:44
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,096 KB
testcase_01 AC 29 ms
10,096 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 28 ms
10,104 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 31 ms
10,212 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 33 ms
10,216 KB
testcase_14 AC 38 ms
10,224 KB
testcase_15 AC 35 ms
10,220 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

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] * (n + 5)
for p in prime:
    if p == 0:
        break
    win[p + 2] = True
    win[p + 3] = True

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

0