def gcd(x, y)
  x, y = y, x if x < y
  while true
    r = x % y
    break if r == 0
    x = y
    y = r
  end
  return y
end

def lcm(x, y)
  g = gcd(x, y)
  return x * y / g
end

a, b, c, d = gets.split.map(&:to_i)
n_b_c = b / c
n_a1_c = (a - 1) / c
n_b_d = b / d
n_a1_d = (a - 1) / d
n_b_cd = b / lcm(c, d)
n_a1_cd = (a - 1) / lcm(c, d)

puts (b - a + 1) - ((n_b_c - n_a1_c) + (n_b_d - n_a1_d) - (n_b_cd - n_a1_cd))
