main :: IO ()
main = do
  [a, b, c, d] <- map (read :: String -> Int) . words <$> getLine
  let e = b - a
  let f = lcm c d
  print $ if c /= d then e - (e `div` c) - (e `div` d) + (e `div` f) else e - (e `div` c)
