結果

問題 No.7 プライムナンバーゲーム
ユーザー goto_isyukugoto_isyuku
提出日時 2017-06-04 07:10:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,135 ms / 5,000 ms
コード長 908 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-09 04:21:03
合計ジャッジ時間 8,871 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 1,094 ms
11,264 KB
testcase_03 AC 95 ms
11,008 KB
testcase_04 AC 46 ms
10,880 KB
testcase_05 AC 45 ms
10,880 KB
testcase_06 AC 348 ms
11,008 KB
testcase_07 AC 228 ms
11,008 KB
testcase_08 AC 121 ms
11,008 KB
testcase_09 AC 510 ms
11,136 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 240 ms
11,136 KB
testcase_12 AC 837 ms
11,264 KB
testcase_13 AC 847 ms
11,264 KB
testcase_14 AC 1,135 ms
11,264 KB
testcase_15 AC 1,051 ms
11,264 KB
testcase_16 AC 986 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

def ints_from_2(x):
  l = []
  for i in range(x - 1):
    l.append(i + 2)
  
  return l

def sieve(x):
  l = ints_from_2(x)
  ans = []
  
  car = l[0]
  cdr = l[1:]
  
  while car ** 2 < x:
      cdr = [x for x in cdr if x % car != 0]
      
      ans.append(car)
      car = cdr[0]
      cdr = cdr[1:]
      
  ans = ans + [car] + cdr
  
  return ans

pl = sieve(n)

plp2 = [x + 2 for x in pl]
plp3 = [x + 3 for x in pl]

result = [0 for x in range(n + 4)]

result[2] = -1 # means 2
result[3] = -1

for x in plp2:
  result[x] = 1
  
for x in plp3:
  result[x] = 1
  
for x in range(len(result)):
  if x != 0 and x != 1:
    if result[x] == 0:
      tmp = True
      for a in [b for b in pl if b < x]:
        if result[x - a] == -1:
          tmp = False
      
      if tmp:
        result[x] = -1
      else:
        result[x] = 1

if result[n] == 1:
  print("Win")
else:
  print("Lose")
0