結果

問題 No.7 プライムナンバーゲーム
ユーザー s_shoheis_shohei
提出日時 2020-06-13 13:20:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 614 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 64,184 KB
最終ジャッジ日時 2024-04-09 04:55:03
合計ジャッジ時間 2,223 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,828 KB
testcase_01 AC 38 ms
52,748 KB
testcase_02 AC 95 ms
63,016 KB
testcase_03 AC 50 ms
61,780 KB
testcase_04 AC 51 ms
61,520 KB
testcase_05 AC 47 ms
60,848 KB
testcase_06 AC 64 ms
63,268 KB
testcase_07 AC 58 ms
62,832 KB
testcase_08 AC 57 ms
62,236 KB
testcase_09 AC 73 ms
63,524 KB
testcase_10 AC 41 ms
52,460 KB
testcase_11 AC 62 ms
63,372 KB
testcase_12 AC 83 ms
63,864 KB
testcase_13 AC 83 ms
63,416 KB
testcase_14 AC 95 ms
62,900 KB
testcase_15 AC 93 ms
64,184 KB
testcase_16 AC 90 ms
63,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

_,primes=sieve(n)

table=[False]*(n+1)

table[0]=True # win
table[1]=True

for num in range(2,n+1):
    for p in primes:
        if p>num:
            break
        if not table[num-p]:
            table[num]=True
if table[-1]:
    print("Win")
else:
    print("Lose")
0