Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import System.IO
  2.  
  3. isOdd :: Integer -> Integer -> Integer
  4. isOdd x y =
  5.  if x > y then 0
  6.  else if mod x 2 /= 0 && mod y 2 /= 0 then ((x + y) `div` 2) * ( (y - x + 2) `div` 2) -- if both numbers are odd
  7.  else if mod x 2 == 0 && mod y 2 == 0 then (((x + y) `div` 2) * (((y - 1) - (x + 1) + 2) `div` 2)) -- if both numbers are even
  8.  else if mod x 2 /= 0 && mod y 2 == 0 then (((x + y - 1) `div` 2) * (((y - 1) - x + 2) `div` 2)) -- if x is odd
  9.  else if mod x 2 == 0 && mod y 2 /= 0 then (((x + 1 + y) `div` 2) * ((y - (x + 1) + 2) `div` 2)) -- if y is odd
  10.  else 0
  11.  
  12. resultFunction cases 0 = putStrLn "Program ended"
  13.  
  14. resultFunction cases c = do
  15.   let i = show cases
  16.  
  17.   putStrLn "write x:"
  18.   x <- readLn :: IO Integer
  19.   putStrLn "write y:"
  20.   y <- readLn :: IO Integer
  21.   putStrLn ("Case " ++ i ++ ":")
  22.   print (isOdd x y)
  23.   resultFunction (cases+1) (c - 1)
  24.  
  25. main = do
  26.    input1 <- getLine
  27.    let cases = 1
  28.    let input1Number = (read input1 :: Integer)
  29.    resultFunction cases input1Number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement