import Control.Applicative
import Control.Monad
import Data.List

main = do
  [a, b, c, d] <- map (read::String -> Integer) . words <$> getLine
  let gcd = calcGcd c d
      lcm = (c * d) `div` gcd
      a_num = (a - 1) `div` c + (a - 1) `div` d - (a - 1) `div` lcm
      b_num = b `div` c + b `div` d - b `div` lcm
  print $ b - a + 1 - b_num + a_num

calcGcd::Integer -> Integer -> Integer
calcGcd x y
 | x < y = calcGcd y x
 | x `mod` y == 0 = y
 | otherwise = calcGcd y (x `mod` y)