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 c_b = b / c + b / d - b / lcm c d
let c_a = (a - 1) / c + (a - 1) / d - (a - 1) / lcm c d
let _ = b - a + 1 - (c_b - c_a) |> Printf.printf "%d\n"