結果

問題 No.7 プライムナンバーゲーム
ユーザー momoyuumomoyuu
提出日時 2022-03-22 02:39:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 604 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 05:07:19
合計ジャッジ時間 5,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
11,008 KB
testcase_01 AC 246 ms
11,008 KB
testcase_02 AC 243 ms
11,008 KB
testcase_03 AC 244 ms
11,008 KB
testcase_04 AC 240 ms
11,008 KB
testcase_05 AC 246 ms
11,008 KB
testcase_06 AC 252 ms
11,008 KB
testcase_07 AC 239 ms
11,008 KB
testcase_08 AC 269 ms
11,008 KB
testcase_09 AC 258 ms
11,008 KB
testcase_10 AC 250 ms
11,008 KB
testcase_11 AC 245 ms
10,880 KB
testcase_12 AC 244 ms
11,008 KB
testcase_13 AC 244 ms
11,008 KB
testcase_14 AC 251 ms
11,008 KB
testcase_15 AC 246 ms
11,008 KB
testcase_16 AC 244 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrime(n):
    """
    素数かどうかを判定する。
    O(√n)
    """

    import math
    m = math.floor(math.sqrt(n))
    for i in range(2,m+1):
        if n%i == 0:
            return False
    return True

N = int(input())
m = 10000 + 1
l = [0 for _ in range(m)]
l[2] = -1
l[3] = -1
l[4] = 1
d = []
for i in range(2,m):
    if isPrime(i):
        d.append(i)

for i in range(2,m):
    if l[i] == 0:
        l[i] = -1
    if l[i] == 1:
        continue
    for j in d:
        if i+j >= m:
            break
        l[i+j] = 1

if l[N] == -1:
    print("Lose")
else:
    print("Win")


0