{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [a, b, c, d] <- readIntegers
  print $ solve a b c d

solve :: Integer -> Integer -> Integer -> Integer -> Integer
solve a b c d = b - a + 1 - (b `div` c + b `div` d - (a - 1) `div` c - (a - 1) `div` d - b `div` (lcm c d) + (a - 1) `div` (lcm c d))
-- 4 9 2 3
-- 6 - (4 + 3 - 1 - (2 + 1 + 0))

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine