a, b, c, d = gets.split.map(&:to_i)
mc = (Rational(b, c).floor) - (Rational(a, c).ceil) + 1
md = (Rational(b, d).floor) - (Rational(a, d).ceil) + 1
mcd = (Rational(b, c.lcm(d)).floor) - (Rational(a, c.lcm(d)).ceil) + 1
multiples = mc + md - mcd
puts (b - a + 1 - multiples)