Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.IO
- isOdd :: Integer -> Integer -> Integer
- isOdd x y =
- if x > y then 0
- 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
- 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
- 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
- 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
- else 0
- resultFunction cases 0 = putStrLn "Program ended"
- resultFunction cases c = do
- let i = show cases
- putStrLn "write x:"
- x <- readLn :: IO Integer
- putStrLn "write y:"
- y <- readLn :: IO Integer
- putStrLn ("Case " ++ i ++ ":")
- print (isOdd x y)
- resultFunction (cases+1) (c - 1)
- main = do
- input1 <- getLine
- let cases = 1
- let input1Number = (read input1 :: Integer)
- resultFunction cases input1Number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement