結果

問題 No.25 有限小数
ユーザー むらため
提出日時 2017-08-14 23:36:46
言語 Nim
(2.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 3,444 ms
コンパイル使用メモリ 70,360 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-30 02:33:42
合計ジャッジ時間 4,292 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(4, 51) Warning: Number of spaces around '-' is not consistent [Spacing]
/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, 57) Warning: imported and not used: 'macros' [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, 45) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,macros,rationals
template get*():string = stdin.readLine()
proc toSeq(str:string):seq[char] = result = @[];(for s in str: result &= s)
proc split(n:int):auto = ($n).toSeq().mapIt(it.ord- '0'.ord)

proc factorize(base:var int, n:int):int =
  result = 0
  while base mod n == 0:
    result += 1
    base = base div n

let
  N = get().parseInt()
  M = get().parseInt()
var
  r = (N // M) * (1//1)
  (n,m) = (r.num,r.den)
  m2 = m.factorize(2)
  m5 = m.factorize(5)
if m != 1 : echo -1 # 2,5以外があるとダメ
elif m2 > m5 : echo 5
elif m2 == m5 : echo n.split().filterIt(it != 0)[^1] # / 1000
elif m2 < m5 : echo n.split()[^1].`*`(1 shl (m5 - m2)).split()[^1] # /1000に
0