{- A
f :: [Char] -> String
f (x:y:ys)
    | x == y = "Bad"
    | ys == [] ="Good"
    | otherwise = f (y:ys)

main = getLine >>= putStrLn . f
-}


{- B
del :: Int -> Int -> Int -> Int
del d x y
    | d == abs x = y
    | d == abs y = x
    | otherwise = x + y

f :: [Int] -> String
f (n:l:xs) = do
    let x = [l+i-1 | i <- [1..n] ]
    let d = minimum $ map abs x
    show $ foldr1 (del d) x

main = getLine >>= putStrLn . f . map read . words
-}

{- C, TLE
f (a:b:c:d:xs) = length [x | x <- [a..b], x `mod` c /= 0 && x `mod` d /= 0 ]
-}

g b x n c d
    | x <= b = if x `div` c /= 0 && x `div` d /= 0 then g b (x+1) (n+1) c d else g b (x+1) n c d
    | otherwise = n

f (a:b:c:d:xs) = g b a 0 c d

main = getLine >>= putStrLn . show . f . map read . words
