a,b,c,d = gets.split.map(&:to_i)
range = b-a+1
def baisu(n,m,div)
  if n == m
    if n%div == 0
      return 1
    else
      return 0
    end
  end
  x = ((n.to_f)/div)
  y = ((m.to_f)/div)
  if x%1 == 0
    if y%1 == 0
      (y-x+1).to_i
    else
      ((y.to_i)-x+1).to_i
    end
  else
    if y%1 == 0
      (y-(x.ceil)+1).to_i
    else
      ((y.to_i)-(x.ceil)+1).to_i
    end
  end
end

range -= ((baisu(a,b,c)+baisu(a,b,d))-baisu(a,b,c.lcm(d)))
puts range