
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    [a,b,c,d] <- r'
    let nC = div b c - div' a c
    let nD = div b d - div' a d
    --print (nC,nD)
    let nCD = div b (lcm c d) - div' a (lcm c d)
    --print (nCD)
    print $ (b-a+1)-(nC+nD)+nCD

div' x y = if y * (div x y) == x then div x y - 1 else div x y
