結果

問題 No.7 プライムナンバーゲーム
ユーザー むらためむらため
提出日時 2020-06-01 08:33:39
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 770 bytes
コンパイル時間 4,038 ms
コンパイル使用メモリ 68,088 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-13 09:00:12
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 62) Warning: imported and not used: 'tables' [UnusedImport]
/home/judge/data/code/Main.nim(1, 50) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport]
/home/judge/data/code/Main.nim(1, 35) Warning: imported and not used: 'algorithm' [UnusedImport]
/home/judge/data/code/Main.nim(1, 57) Warning: imported and not used: 'sets' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,sets,tables
template get():string = stdin.readLine()

proc getIsPrimes(n:int) :seq[bool] =
  result = newSeqWith(n+1,true)
  result[0] = false
  result[1] = false
  for i in 2..n.float.sqrt.int :
    if not result[i]: continue
    for j in countup(i*2,n,i):
      result[j] = false

proc getPrimes():seq[int] =
  const isPrime = getIsPrimes(10000)
  result = newSeq[int](0)
  for i,p in isPrime:
    if p : result.add(i)


# lose 2 3 ... <=> win 0 1 4 5 6 7 ...
let primes = getPrimes()
let N = get().parseInt
var win = newSeqWith(N,false)
win[0] = true
win[1] = true
for i in 2..N:
  for p in primes:
    if i - p < 0 : break
    if not win[i-p]:
      win[i] = true
      break
echo if win[N]: "Win" else: "Lose"
0