let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)
let lcm n m = n / gcd n m * m

let () = Scanf.scanf "%d %d %d %d" @@ fun a b c d ->
  Printf.printf "%d\n" @@
  b - a + 1
  - (b / c - (a - 1) / c)
  - (b / d - (a - 1) / d)
  + (b / lcm c d - (a - 1) / lcm c d)