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

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

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

divAll2 :: [Integer] -> [Integer]
divAll2 a = if all (\t -> mod t 2 == 0) a then divAll2 $ map (`div` 2) a else a

isValid :: [Integer] -> Bool
isValid as = (all (\t -> mod t 2 == 1) $ divAll2 as) && (all (\t -> mod t 2 == 1) as)

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

ans :: [[Integer]] -> Integer
ans [[n, m], a] = if isValid a then ((`div` 2) $ (+) 1 $ div m $ (`div` 2) $ lcmList m a) else 0
