
main = do 
    [a, b, c, d] <- map (read :: String -> Integer). words <$> getLine

    let d1 = div (a-1) c
    let d2 = div (a-1) d
    let d3 = div (a-1) (lcm c d)
    let d4 = div b c
    let d5 = div b d
    let d6 = div b (lcm c d)

    print $ b - a + 1 - ((d4 + d5 - d6) - (d1 + d2 - d3))

