結果

問題 No.7 プライムナンバーゲーム
ユーザー むらためむらため
提出日時 2017-07-30 21:19:47
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 835 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 68,436 KB
最終ジャッジ日時 2024-04-27 02:28:25
合計ジャッジ時間 1,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/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) Error: cannot open file: queues

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables
template get():string = stdin.readLine()
template times(n:int,body:untyped): untyped = (for _ in 0..<n: body)

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(n:int):seq[int] =
  let isPrime = getIsPrimes(n)
  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 N = get().parseInt
let primes = getPrimes(N)
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
echo if win[N]: "Win" else: "Lose"
0