-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [a,b,c,d] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ if c == d
          then (b - b `quot` c) - (a - 1 - (a - 1) `quot` c)
          else let f n = n - n `quot` c - n `quot` d + n `quot` (c * d)
               in f b - f (a - 1)
