main = do
  [a,b,c,d] <- map read . words <$> getLine :: IO [Int]
  let l = c*d `div` gcd c d
  let ans = b - ((b`div`c) + (b`div`d) - (b`div`l))
  print $ ans - ((a-1) - (((a-1)`div`c) + ((a-1)`div`d) - ((a-1)`div`l)))
  

-- 最大公約数を求める
mygcd :: Int -> Int -> Int 
mygcd a b
  | b == 0 = a
  | otherwise = mygcd a (a`mod`b)