main :: IO ()
main = do
  [a, b, c, d] <- map (read :: String -> Int) . words <$> getLine
  let e = lcm c d
  let bb = b - (b `div` c) - (b `div` d) + (b `div` e)
  let ad = a - 1
  let aa = ad - (ad `div` c) - (ad `div` d) + (ad `div` e)
  print $ bb - aa
