a, b, c, d = gets.chomp.split.map(&:to_i)

c_num = (b / c) - ((a - 1) / c)
d_num = (b / d) - ((a - 1) / d)

# 最小公倍数
e = [c, d].max
f = [c, d].min

while true do
  q = e / f

  if e % f == 0
    break
  else
    r = e % f
  end

  e = f
  f = r
end

g = c / r * d

g_num = (b / g) - (a - 1) / g
puts b - a + 1 - (c_num + d_num - g_num)