#n = gets.chomp.to_i
a,b,c,d = gets.chomp.split(" ").map(&:to_i);
class Array
  def lcm
    self.inject{|a,b| a.lcm(b)}
  end
end

a -= 1
c_d = [c,d].lcm
under_a = a - (a/c) - (a/d) + (a/c_d) 
under_b = b - (b/c) - (b/d) + (b/c_d)

puts under_b - under_a