a, b, c, d = gets.chomp.split(" ").map(&:to_i)
result = 0
c_c = c
d_d = d
while c_c <= b || d_d <= b
  if c_c >= a && c_c <= b
    result += 1
  end
  if d_d >= a && d_d <= b
    result += 1
  end
  c_c += c
  d_d += d
end

min = c.lcm(d)
min_m = min
while min_m <= b
  if min_m >= a
    result -= 1
  end
  min_m += min
end

puts ((b - a + 1) - result)