object Main extends App {
  def gcd(a: Long,b: Long): Long = if(b ==0) a else gcd(b, a%b)
  
  val Array(a,b,c,d) = readLine.split(" ").map(_.toLong)
  val am = a-1
  val cd = c*d/gcd(c,d)
  println(b-am - (b/c-am/c) - (b/d-am/d) + (b/cd-am/cd))
}