結果

問題 No.7 プライムナンバーゲーム
ユーザー yama6k16yama6k16
提出日時 2019-12-02 16:16:53
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 576 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 8,940 KB
最終ジャッジ日時 2023-07-24 21:28:48
合計ジャッジ時間 4,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,620 KB
testcase_01 AC 17 ms
8,632 KB
testcase_02 AC 559 ms
8,940 KB
testcase_03 AC 52 ms
8,796 KB
testcase_04 AC 26 ms
8,580 KB
testcase_05 AC 26 ms
8,540 KB
testcase_06 AC 179 ms
8,648 KB
testcase_07 AC 124 ms
8,724 KB
testcase_08 AC 64 ms
8,556 KB
testcase_09 AC 262 ms
8,864 KB
testcase_10 AC 16 ms
8,524 KB
testcase_11 AC 124 ms
8,792 KB
testcase_12 AC 407 ms
8,852 KB
testcase_13 AC 425 ms
8,768 KB
testcase_14 AC 576 ms
8,768 KB
testcase_15 AC 528 ms
8,720 KB
testcase_16 AC 509 ms
8,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
import math
def prime(n):
    l = math.floor(n ** (1/2))
    if n == 2:
        return 1
    elif n == 1:
        return 0
    for i in range(2,l + 1):
        if n % i == 0:
            return 0
    return 1

N_list = [0] * (N + 1)
N_list[2] = 0
N_list[3] = 0
#0 ... formar lose
end = 0
p_list = []
for i in range(2,N + 1):
    if prime(i) == 1:
        p_list.append(i)
if prime(N) == 1:
    p_list.remove(N)
#make win-lose list
N_list = [0] * (N+1)
N_list[0] = -1
N_list[1] = -1
if N > 3:    
    for i in range(4,N+1):
        for line in p_list:
            if i  - line > 1:
                if N_list[i - line] == 0:
                    N_list[i] = 1
                    break
 
if N_list[N] == 1:
    print("Win")
else:
    print("Lose")
0