結果

問題 No.7 プライムナンバーゲーム
ユーザー piconic_X
提出日時 2016-08-23 00:25:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 827 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-11-07 22:48:35
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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