結果

問題 No.7 プライムナンバーゲーム
ユーザー 👑 KazunKazun
提出日時 2020-07-29 01:19:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 896 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 72,028 KB
最終ジャッジ日時 2024-04-09 04:58:51
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,992 KB
testcase_01 AC 39 ms
53,696 KB
testcase_02 AC 152 ms
71,724 KB
testcase_03 AC 59 ms
65,920 KB
testcase_04 AC 51 ms
64,832 KB
testcase_05 AC 53 ms
64,432 KB
testcase_06 AC 83 ms
69,284 KB
testcase_07 AC 75 ms
67,404 KB
testcase_08 AC 63 ms
67,508 KB
testcase_09 AC 99 ms
69,860 KB
testcase_10 AC 37 ms
53,072 KB
testcase_11 AC 74 ms
68,124 KB
testcase_12 AC 123 ms
70,672 KB
testcase_13 AC 127 ms
71,168 KB
testcase_14 AC 150 ms
71,960 KB
testcase_15 AC 144 ms
72,028 KB
testcase_16 AC 138 ms
70,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Sieve_of_Eratosthenes(N,mode=False):
    """Nまでのエラトステネスの篩を実行

    N:自然数
    mode:False->素数のリスト,True->素数かどうかのリスト
    (False->[2,3,5,...],True->[False,False,True,True,False,True,...])
    """

    T=[True]*(N+1)
    T[0]=T[1]=0
    a=2
    while a*a<=N:
        if T[a]:
            b=a*a
            while b<=N:
                T[b]=False
                b+=a
        a+=1

    if mode:
        return T
    else:
        return [k for k in range(N+1) if T[k]]
#-----------------------------------------------------------
N=int(input())
P=Sieve_of_Eratosthenes(N,False)

inf=float("inf")
M=[inf]*(N+1)
M[2]=M[3]=0

for i in range(4,N+1):
    X=set()
    for p in P:
        if i<p:
            break
        X.add(M[i-p])

    t=0
    while t in X:
        t+=1
    M[i]=t

if M[i]:
    print("Win")
else:
    print("Lose")

0