結果

問題 No.7 プライムナンバーゲーム
ユーザー piconic_Xpiconic_X
提出日時 2016-08-22 15:02:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 747 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-25 11:15:25
合計ジャッジ時間 5,380 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 632 ms
10,752 KB
testcase_03 WA -
testcase_04 AC 34 ms
10,880 KB
testcase_05 WA -
testcase_06 AC 196 ms
10,752 KB
testcase_07 AC 141 ms
10,752 KB
testcase_08 AC 75 ms
10,752 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 143 ms
10,752 KB
testcase_12 AC 457 ms
10,752 KB
testcase_13 AC 477 ms
10,752 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 559 ms
10,752 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:
                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'

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

main()
0