結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 658 ms
11,136 KB
testcase_03 AC 75 ms
10,880 KB
testcase_04 AC 41 ms
10,880 KB
testcase_05 AC 40 ms
10,880 KB
testcase_06 AC 222 ms
11,008 KB
testcase_07 AC 159 ms
11,008 KB
testcase_08 AC 84 ms
11,008 KB
testcase_09 AC 325 ms
11,008 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 150 ms
11,008 KB
testcase_12 AC 479 ms
11,008 KB
testcase_13 AC 498 ms
10,880 KB
testcase_14 AC 645 ms
11,136 KB
testcase_15 AC 628 ms
11,136 KB
testcase_16 AC 573 ms
11,136 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