結果

問題 No.7 プライムナンバーゲーム
コンテスト
ユーザー togatoga
提出日時 2015-08-15 07:47:13
言語 PyPy2
(7.3.20)
コンパイル:
pypy2 -m py_compile _filename_
実行:
/usr/bin/pypy2 Main.pyc
結果
AC  
実行時間 1,360 ms / 5,000 ms
+ 421µs
コード長 622 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 65 ms
コンパイル使用メモリ 80,768 KB
実行使用メモリ 90,112 KB
最終ジャッジ日時 2026-07-17 18:54:03
合計ジャッジ時間 10,212 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(1 << 30)
N = input()
dp = [-1 for i in range(10010)]
prime = [True for i in range(10010)]
def sieve():
    prime[0] = False
    prime[1] = False
    for i in range(2, 10010):
        if (prime[i]):
            for j in range(i * i, 10010, i):
                prime[j] = False


def memo(pos):
    if (pos == 0 or pos == 1):
        return True
    win = False
    if (dp[pos] >= 0):
        return dp[pos]
    for i in range(2, pos):
        if (prime[i]):
            win |= not memo(pos - i)
    dp[pos] = win
    return win

sieve()
if (memo(N)):
    print "Win"
else:
    print "Lose"
0