def gcd (a, b)
  s = a < b ? a : b
  l = a < b ? b : a
  if l % s == 0 then
    s
  else
    gcd(s, (l % s))
  end
end

def lcm (a, b)
  a * b / gcd(a, b)
end

A, B, C, D = STDIN.gets.chomp.split(" ").map(&:to_i)

all = ((B / C) + (B / D)) - (B / lcm(C, D))
part = (((A - 1) / C) + ((A - 1) / D)) - ((A - 1) / lcm(C, D))
puts  (B - A + 1) - (all - part)
