結果

問題 No.7 プライムナンバーゲーム
ユーザー titiatitia
提出日時 2021-11-01 15:07:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 677 ms / 5,000 ms
コード長 585 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-09 05:05:33
合計ジャッジ時間 5,984 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
11,264 KB
testcase_01 AC 34 ms
11,264 KB
testcase_02 AC 677 ms
11,392 KB
testcase_03 AC 102 ms
11,264 KB
testcase_04 AC 59 ms
11,264 KB
testcase_05 AC 58 ms
11,264 KB
testcase_06 AC 256 ms
11,392 KB
testcase_07 AC 199 ms
11,392 KB
testcase_08 AC 113 ms
11,392 KB
testcase_09 AC 336 ms
11,392 KB
testcase_10 AC 34 ms
11,392 KB
testcase_11 AC 193 ms
11,264 KB
testcase_12 AC 496 ms
11,392 KB
testcase_13 AC 524 ms
11,392 KB
testcase_14 AC 644 ms
11,392 KB
testcase_15 AC 661 ms
11,520 KB
testcase_16 AC 580 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

x=10**4

import math 
L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]


N=int(input())

DP=[0]*(N+1)

for i in range(4,N+1):
    for j in Primes:
        if i-j>=2 and DP[i-j]==0:
            DP[i]=1
            break
    else:
        DP[i]=0

if DP[N]==0:
    print("Lose")
else:
    print("Win")
0