let a, b, c, d = Scanf.scanf " %d %d %d %d" @@ fun a b c d -> a, b, c, d
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec lcm a b = a / gcd a b * b
let f x = x / c + x / d - x / lcm c d
let _ = b - a + 1 - (f b - f (a - 1)) |> Printf.printf "%d\n"