main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine :: IO [Integer]
  let br = b - b `div` c - b `div` d + b `div` lcm c d
  let ar = (a - 1) - (a - 1) `div` c - (a - 1) `div` d + (a - 1) `div` lcm c d
  print $ br - ar