結果

問題 No.7 プライムナンバーゲーム
ユーザー piconic_Xpiconic_X
提出日時 2016-08-23 00:11:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 364 ms / 5,000 ms
コード長 810 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-09 04:02:13
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 363 ms
11,776 KB
testcase_03 AC 50 ms
10,880 KB
testcase_04 AC 34 ms
10,880 KB
testcase_05 AC 35 ms
10,752 KB
testcase_06 AC 129 ms
11,008 KB
testcase_07 AC 94 ms
11,136 KB
testcase_08 AC 58 ms
11,008 KB
testcase_09 AC 175 ms
11,648 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 94 ms
11,008 KB
testcase_12 AC 267 ms
11,648 KB
testcase_13 AC 283 ms
11,648 KB
testcase_14 AC 364 ms
11,776 KB
testcase_15 AC 349 ms
11,648 KB
testcase_16 AC 323 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes(N):
    ps = []
    for i in range(3, N, 2):
        for p in ps:
            if i % p == 0:
                break
            else:
                continue
        else:
            ps.append(i)
    ps.insert(0, 2)
    return ps

def game(N, ps):
    won = set([0,1])
    lost = set()
    for n in range(2, N+1):
        for p in ps:
            n_ = n - p
            if n_ < 0:
                lost.add(n)
                break
            elif n_ in lost:
                won.add(n)
                break
            elif n_ in won:
                continue
        else:
            lost.add(n)
    if N in won:
        return 'Win'
    elif N in lost:
        return 'Lose'
    else:
        return 'Kill me'

def main():
    N = int(input())
    ps = primes(N)
    print(game(N, ps))

main()
0