open List
let gcd (a, b) =
  let rec gcd' (a, b)= 
    if b = 0 then a else gcd' (b, a mod b)
  in if a > b then gcd' (a, b)
     else gcd' (b, a)

let i_inp_list : unit -> int list = fun () ->
  let inp_split = Str.split (Str.regexp " ") (input_line stdin) in
  map (fun x -> int_of_string x) (inp_split)

let () =
  let [a;b;c;d] = i_inp_list () in
  let enum_can_div k =
    b / k - (a - 1) / k in
  let y_c = enum_can_div c in
  let y_d = enum_can_div d in
  let y_cd = enum_can_div (c / gcd (c, d) * d) in
  let ans = (b - a + 1) - (y_c + y_d - y_cd) in
  print_int ans;
  print_newline ()
    