object Main extends App {

  val Array(a,b,c,d) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

  def solve(): Long = {
    b - (a-1) - calcCount(b, c, d) + calcCount(a-1, c, d)
  }

  def calcLCM(x: Long, y: Long): Long = {
    (x * y) /  calcGCD(x, y)
  }

  def calcGCD(x: Long, y: Long): Long = {
    if(y == 0) x
    else calcGCD(y, x % y)
  }

  def calcCount(target: Long, x: Long, y: Long): Long = {
    val lcm = calcLCM(x, y)
    (target / x) + (target / y) - (target / lcm)
  }


  println(solve)

}