結果

問題 No.7 プライムナンバーゲーム
ユーザー nidosinonidosino
提出日時 2017-06-03 07:12:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,170 ms / 5,000 ms
コード長 1,686 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-09 04:21:35
合計ジャッジ時間 15,352 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 2,170 ms
10,880 KB
testcase_03 AC 151 ms
10,880 KB
testcase_04 AC 59 ms
10,752 KB
testcase_05 AC 58 ms
10,752 KB
testcase_06 AC 619 ms
10,752 KB
testcase_07 AC 424 ms
10,752 KB
testcase_08 AC 209 ms
10,752 KB
testcase_09 AC 952 ms
10,752 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 435 ms
10,752 KB
testcase_12 AC 1,482 ms
11,008 KB
testcase_13 AC 1,620 ms
10,880 KB
testcase_14 AC 2,123 ms
10,880 KB
testcase_15 AC 1,957 ms
10,880 KB
testcase_16 AC 1,884 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
あなたと素数を習ったばかりのEveは、素数のゲームを思いついた。

ゲームの内容は以下のとおりです。
・まず初めに、先攻のプレイヤーに22以上の自然数NNが与えられます。
・その番のプレイヤーはNNに対して、「NN以下(NNも含む)の素数」のどれかで減算する、
その数をN′N′とすると、N′N′が00または11になってしまったら、そのプレイヤーの負けである。
・その後N′N′を新たなNNとし、相手にその数を渡し、以上を繰り返します。

まずあなたが先攻となりゲームを始めます。
この時、どちらも負けないように動くと考える。自然数NNが与えられた時、
あなたが勝つことが出来る場合WinWin、それ以外はLoseLoseを返してください。
'''


def prime_maker(x):
    prime_list = [True] * (x + 1)
    for i in range(2, x + 1):
        if prime_list[i]:
            for j in range(i + 1, x + 1):
                if j % i == 0:
                    prime_list[j] = False
    prime_list1 = []
    for y_num, y in enumerate(prime_list):
        if y:
            prime_list1.append(y_num)

    return prime_list1[2:]


if __name__ == '__main__':

    A = int(input())
    prime_list = prime_maker(A)
    score_list = [False] * (A + 1)
    score_list[0] = True
    score_list[1] = True
    count = 0
    for i in range(2, A + 1):
        for j in prime_list:
            if i >= j and not score_list[i - j]:
                score_list[i] = True
    if score_list[A]:
        print("Win")
    else:
        print("Lose")
0