object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val A, B, C, D = sc.nextLong

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

    val lcm = C * D / gcd(C, D)
    val divideA = (A - 1) - ((A - 1) / C + (A - 1) / D - (A - 1) / lcm)
    val divideB = B - (B / C + B / D - B / lcm)
    println(divideB - divideA)
  }
}