結果

問題 No.2 素因数ゲーム
ユーザー むらためむらため
提出日時 2017-08-12 11:38:25
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,413 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 59,824 KB
最終ジャッジ日時 2023-09-12 14:04:26
合計ジャッジ時間 1,207 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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,macros
macro unpack*(rhs: seq,cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `rhs`;())
  for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
template get*():string = stdin.readLine()
template times*(n:int,body:untyped): untyped = (for _ in 0..<n: body)
template `max=`*(x,y:typed):void = x = max(x,y)
template `min=`*(x,y:typed):void = x = min(x,y)

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] = # [2,3,5,...<n]
  let isPrime = getIsPrimes(n)
  result = @[]
  for i,p in isPrime:
    if p : result &= i

proc getFactors(N:int):seq[int] =
  let primes = getPrimes(N.float.sqrt.int + 1)
  var n = N
  result = @[]
  for p in primes:
    if p >= n : break
    while n mod p == 0:
      result &= p
      n = n div p
  if n != 1: result &= n

proc coundDuplicate[T](arr:seq[T]): auto =
  arr.sorted(cmp[T]).foldl(
    if a[^1].key == b:
      a[0..<a.len-1] & (b, a[^1].val+1)
    else:
      a & (b, 1),
    @[ (key:arr[0],val:0) ])


let
  N = get().parseInt()
  factors = getFactors(N).coundDuplicate().mapIt(it.val)
  nimsum = factors.foldl(a xor b)
echo if nimsum != 0: "Alice" else : "Bob"
0