結果

問題 No.7 プライムナンバーゲーム
ユーザー piconic_Xpiconic_X
提出日時 2016-08-23 00:25:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 827 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-25 11:27:59
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 WA -
testcase_02 AC 78 ms
11,648 KB
testcase_03 AC 33 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 WA -
testcase_06 AC 46 ms
11,392 KB
testcase_07 AC 41 ms
11,136 KB
testcase_08 AC 35 ms
11,008 KB
testcase_09 WA -
testcase_10 AC 31 ms
10,624 KB
testcase_11 AC 42 ms
11,008 KB
testcase_12 AC 65 ms
11,520 KB
testcase_13 AC 67 ms
11,520 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 71 ms
11,648 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)
    ps.reverse()
    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