main = do
    [a,b,c,d] <- map read . words <$> getLine :: IO [Integer]
    let ab = b-a+1
    let c' = (div b c) - (div (a-1) c)
    let d' = (div b d) - (div (a-1) d)
    let cd' = (div b (lcm c d)) - (div (a-1) (lcm c d))
    print $ ab-(c'+d'-cd')