import Data.Ratio

main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine
  print $ solve a b c d

-- |
-- >>> solve 4 9 2 3
-- 2
-- >>> solve 10 40 6 8
-- 23
-- >>> solve 314159265358979323 846264338327950288 419716939 937510582
-- 532105071133627368
solve :: Integer -> Integer -> Integer -> Integer -> Integer
solve a b c d = n - nc - nd + ncd
  where
    n   = b - a + 1
    nc  = floor (b % c) - ceiling (a % c) + 1
    nd  = floor (b % d) - ceiling (a % d) + 1
    ncd = floor (b % (c `lcm` d)) - ceiling (a % (c `lcm` d)) + 1
