結果
問題 | No.2 素因数ゲーム |
ユーザー |
|
提出日時 | 2019-10-17 03:12:58 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,418 bytes |
コンパイル時間 | 4,797 ms |
コンパイル使用メモリ | 76,808 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 13:09:24 |
合計ジャッジ時間 | 5,843 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
コンパイルメッセージ
/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, 50) Warning: imported and not used: 'future' [UnusedImport] /home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'strscans' [UnusedImport]
ソースコード
import sequtils,strutils,strscans,algorithm,math,future,sets,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] = const primes = getPrimes(100_000_000.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"