def solve
  a, b, c, d = gets.split.map(&:to_i)
  v = (a / c).to_i
  w = (a / d).to_i
  x = (b / c).to_i
  y = (b / d).to_i
  total1 = x - v
  total2 = y - w
  total3 = total1 + total2 - (c.gcd(d))
  print b - a - total3
end
solve