import Data.List
main = do
  [a, b, c', d'] <- fmap read . words <$> getLine
  let [c, d] = sort [c', d']
      ac = (a-1) `div` c
      ad = a `div` d
      acd = a ` div` lcm c d
      acd' = a - ac - ad + acd
      bc = (b-1) `div` c
      bd = b `div` d
      bcd = b ` div` lcm c d
      bcd' = b - bc - bd + bcd
  print $ bcd' - acd' + 1
