import Control.Monad
main = print =<< ((pure ans) <*> getInput)

getInts :: IO [Int]
getInts = (pure ((map read) . words)) <*> getLine

getInput :: IO [[Int]]
getInput = replicateM 2 getInts

{-
gcd :: Integer -> Integer -> Integer
gcd a 0 = a
gcd a b = gcd b $ mod a b

lcm :: Integer -> Integer -> Integer
lcm a b = div (a * b) $ gcd a b
-}

lcmList :: Int -> [Int] -> Int
lcmList m = foldl (\a b -> if b > m then m + 1 else lcm a b) 1

ans :: [[Int]] -> Int
ans [[n, m], a] = (`div` 2) $ (+) 1 $ div m $ (`div` 2) $ lcmList m a
