Guest User

Untitled

a guest
Sep 1st, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import qualified Data.List as L
  2. import qualified Data.Maybe as M
  3.  
  4. splitAtDot num = (take n num, drop (n+1) num)
  5. where n = M.fromJust $ L.elemIndex '.' num
  6.  
  7. findReqPower num =
  8. let (i, f) = splitAtDot num in
  9. if f == "0" then 0 else length f
  10.  
  11. mulByPower n num =
  12. let (i, f) = splitAtDot num in
  13. case f of
  14. "0" -> i ++ (take n $ repeat '0') ++ ".0"
  15. f' -> if (n < length f') then i ++ (take n f') ++ "." ++ (drop n f')
  16. else i ++ f' ++ (take (n - (length f')) $ repeat '0') ++ ".0"
  17.  
  18. readInt :: String -> Int
  19. readInt = read . init . init
  20.  
  21. main = do
  22. nums <- words <$> getLine
  23. let powers = map findReqPower nums
  24. let power = L.maximum powers
  25. let listGcd = L.foldl1 gcd . map readInt . map (mulByPower power) $ nums
  26. let ans = (100 * 10 ^ power) `div` listGcd
  27. print ans
Add Comment
Please, Sign In to add comment