fork download
  1. module Main where
  2.  
  3. import Text.Printf
  4. import Control.Monad
  5. import Data.List
  6.  
  7.  
  8. run :: [Double] -> (Int, [Double])
  9. run [a,b,c] =
  10. let d = b^2 - 4*a*c
  11. in case d of
  12. _ | abs a < 1e-308 -> if abs b > 1e-308 then (1,[-c/b]) else (if c/=0 then 0 else -1,[])
  13. _ | d < 0 -> (0, [])
  14. _ | d == 0 -> let root = (-b)/(2*a) in (1, [if root == 0 then 0 else root])
  15. _ -> let roots = map (\d -> ((-b) + d)/(2*a)) $ zipWith (*) [1, (-1)] $ map sqrt [d,d]
  16. in (2, sort roots)
  17.  
  18.  
  19. main = do
  20. (n, roots) <- getLine >>= return . run . map (\x -> fromIntegral $ (read x::Int)) . take 3 . words
  21. mapM_ (printf "%.15f\n") roots
  22.  
Success #stdin #stdout 0.01s 5280KB
stdin
1 -5 2
stdout
2
0.438447187191170
4.561552812808831