結果

問題 No.7 プライムナンバーゲーム
ユーザー shianoshiano
提出日時 2020-06-23 23:33:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 696 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 8,488 KB
最終ジャッジ日時 2023-09-16 20:25:30
合計ジャッジ時間 36,778 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,003 ms
8,308 KB
testcase_01 AC 1,880 ms
8,336 KB
testcase_02 AC 1,934 ms
8,488 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1,896 ms
8,348 KB
testcase_06 AC 1,968 ms
8,288 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1,922 ms
8,420 KB
testcase_10 WA -
testcase_11 AC 1,957 ms
8,324 KB
testcase_12 WA -
testcase_13 AC 1,980 ms
8,400 KB
testcase_14 AC 1,916 ms
8,424 KB
testcase_15 AC 1,887 ms
8,436 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


n = int(input())

MAX = 10002
dp = [-1]*(MAX+5)

is_prime,table = sieve(10005)


for i in range(MAX):
  if is_prime[i]:
    dp[i+3]=1
    
for i in range(4):
  dp[i] = 0
    
for i in range(3,MAX):
  for p in table:
    if p+i <= MAX:
      if dp[p+i] == -1 and dp[i] != -1:
        dp[p+i] = dp[i]+1
        
if dp[n]%2 == 0:
  print('Lose')
else:
  print('Win')
0