結果

問題 No.7 プライムナンバーゲーム
ユーザー goto_isyukugoto_isyuku
提出日時 2017-06-04 07:06:04
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 892 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,064 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2023-10-22 03:37:32
合計ジャッジ時間 7,614 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,220 KB
testcase_01 AC 25 ms
10,220 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

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 sieve(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