結果

問題 No.7 プライムナンバーゲーム
ユーザー convexineqconvexineq
提出日時 2020-11-24 05:15:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 919 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 62,608 KB
最終ジャッジ日時 2024-04-09 05:00:42
合計ジャッジ時間 2,292 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,164 KB
testcase_01 AC 42 ms
58,952 KB
testcase_02 AC 55 ms
61,508 KB
testcase_03 AC 47 ms
62,080 KB
testcase_04 AC 46 ms
61,752 KB
testcase_05 AC 46 ms
61,820 KB
testcase_06 AC 50 ms
61,884 KB
testcase_07 AC 49 ms
62,140 KB
testcase_08 AC 47 ms
62,608 KB
testcase_09 AC 50 ms
61,316 KB
testcase_10 AC 41 ms
59,340 KB
testcase_11 AC 49 ms
61,876 KB
testcase_12 AC 52 ms
61,832 KB
testcase_13 AC 52 ms
61,552 KB
testcase_14 AC 54 ms
61,884 KB
testcase_15 AC 54 ms
62,340 KB
testcase_16 AC 55 ms
61,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(N): #N以下の素数のリストを返す
    #iが素数のときis_prime_list[i]=1,それ以外は0
    N+=1
    is_prime_list = [True]*N
#    is_prime_list[0], is_prime_list[1] = False, False #リストが必要なときはこの2行を有効化
#    for j in range(4,N,2): is_prime_list[j] = False
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_list[i]]

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#a,b,c = map(int,readline().split())

primes = Eratosthenes(10**4)
n = int(input())
dp = [0]*(n+1) # 0: 後手
dp[0]=dp[1]=1

for i in range(2,n+1):
    for p in primes:
        if i < p: break
        if dp[i-p]==0:
            dp[i] = 1
            break

print("Win" if dp[n] else "Lose")
0