結果

問題 No.7 プライムナンバーゲーム
ユーザー nbisconbisco
提出日時 2016-04-10 23:21:25
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 469 ms / 5,000 ms
コード長 540 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-07-24 20:32:38
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,248 KB
testcase_01 AC 16 ms
8,268 KB
testcase_02 AC 446 ms
8,192 KB
testcase_03 AC 43 ms
8,356 KB
testcase_04 AC 24 ms
8,184 KB
testcase_05 AC 24 ms
7,772 KB
testcase_06 AC 143 ms
8,216 KB
testcase_07 AC 99 ms
8,280 KB
testcase_08 AC 53 ms
8,352 KB
testcase_09 AC 205 ms
8,292 KB
testcase_10 AC 16 ms
8,140 KB
testcase_11 AC 117 ms
8,252 KB
testcase_12 AC 319 ms
8,228 KB
testcase_13 AC 397 ms
8,368 KB
testcase_14 AC 462 ms
8,272 KB
testcase_15 AC 469 ms
8,372 KB
testcase_16 AC 395 ms
8,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
#fileencoding: utf-8

def is_prime(n,primes):
    for i in primes[1:]:
        if i > (n//2):
            break
        if n % i == 0:
            return False
    return True

N = int(input())
primes = [2]
for i in range(3,N+1,2):
    if is_prime(i,primes):
        primes.append(i)

memo = [0] * 10001
memo[0] = memo[1] = 1
for i in range(2,N+1):
    for p in primes:
        if p > i:
            break
        elif memo[i-p] == 0:
            memo[i] = 1
            break
print("Win" if memo[N] == 1 else "Lose")
0