fun main(args: Array<String>){
  val values = readLine()!!.split(" ")
  val a = values[0].toLong()
  val b = values[1].toLong()
  val c = values[2].toLong()
  val d = values[3].toLong()
  val diff: Long = b - a
  val count: Long = diff + 1
  
  // calc e
  val multi: Long = c * d
  var big: Long = c
  var small: Long = d 
  var tmp: Long = 0
  if (big < small) {
    tmp = big
    big = small
    small = tmp
  }
  var e: Long = big % small
  while (e != 0.toLong()) {
    big = small
    small = e
    e = big % small
  }
  e = multi / small

  // c
  var sa_c: Long = 0
  if (a % c == 0.toLong()) {
    sa_c = a
  } else {
    sa_c = a + (c - a % c)
  }
  val ea_c: Long = b - (b % c)
  val da_c: Long = ea_c - sa_c
  val sum_c: Long = da_c / c + 1
  
  // d
  var sa_d: Long = 0
  if (a % d == 0.toLong()) {
    sa_d = a
  } else {
    sa_d = a + (d - a % d)
  }
  val ea_d: Long = b - (b % d)
  val da_d: Long = ea_d - sa_d
  val sum_d: Long = da_d / d + 1
  
  // e(-)
  var sa_e: Long = 0
  if (a % e == 0.toLong()) {
    sa_e = a
  } else {
    sa_e = a + (e - a % e)
  }
  val ea_e: Long = b - (b % e)
  val da_e: Long = ea_e - sa_e
  val sum_e: Long = da_e / e + 1
  
  val result: Long = count - sum_c - sum_d + sum_e
  println(result)
}
