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