ceilDiv :: Integer -> Integer -> Integer
ceilDiv x y = ceiling ((fromIntegral x) / (fromIntegral y))

calc :: Integer -> Integer -> Integer -> Integer
calc a b c | b < x = 0
           | otherwise = div (b - x) c 
    where x = c * (ceilDiv a c)

main = do
    [a, b, c, d] <- map read . words <$> getLine  
    print $ (b - a) - (calc a b c) - (calc a b d) + (calc a b (lcm c d))
