import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST

main :: IO ()
main = do
  [a,b,c,d] <- map read.words <$> getLine :: IO [Int]
  let f x = if a `mod` x == 0 then (+1) $ (b - a) `div` x else (+1) $ ( b - ((*x) $ (a `div` x) + 1)) `div` x
  putStrLn $ show $ b - a + 1 - ((f c) + (f d) - (f $ lcm d c))
