module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Integer
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map int . words
printer = unlines . (:[]) . show

solver (a:b:c:d:ss) = result -- [uc,cc,dc,cdc,result]
  where
    result = uc - cc - dc + cdc

    uc = b - a + 1

    cc =
      if a <= (b`div`c)*c && (b`div`c)*c <= b
      then
        b `div` c + 1 -
        (a `div` c + if a `mod` c == 0 then 0 else 1)
      else
        0

    dc = 
      if a <= (b`div`d)*d && (b`div`d)*d <= b
      then
        b `div` d + 1 -
        (a `div` d + if a `mod` d == 0 then 0 else 1)
      else
        0

    cd = c `div` ( gcd c d ) * d
    cdc = 
      if a <= (b`div`cd)*cd && (b`div`cd)*cd <= b
      then
        b `div` cd + 1 -
        (a `div` cd + if a `mod` cd == 0 then 0 else 1)
      else
        0

