solver :: Int -> Int -> Int -> Int -> Int
solver a b c d =
  let d_ab x = (div b x) - (div (a - 1) x)
   in (b - a + 1) - ((d_ab c) + (d_ab d) - (d_ab (lcm c d)))

main :: IO ()
main = do
  a:b:c:d:_ <- map read . words <$> getLine
  print $ solver a b c d
