import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (a : b : c : d : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    f = subtract <$> g <*> h
      where
        g x = let (q, r) = divMod a x in if r == 0 then q else succ q
        h = succ . div b
  print $ (b - a + 1) - f c - f d + f (lcm c d)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
