import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

calc a b k i ns
  | n >= a && n <= b && notElem n ns = calc a b k i (n:ns)
  | n > b = ns
  | otherwise = calc a b k (i+1) ns
  where
    n = k * i

main = do
  [a, b, c, d] <- getIntList
  let ns = calc a b c (a `div` c) []
  let ns' = calc a b d (a `div` d) ns
  print $ (b - a + 1) - length ns'

