object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val _A, _B = sc.nextBigInteger()
    val _C, _D = sc.nextLong()

    val A = BigInt(_A)
    val B = BigInt(_B)

    def gcd(a: Long, b: Long): Long =
      if (b == 0) a
      else gcd(b, a % b)

    def lcm(a: Long, b: Long): Long =
      a * b / gcd(a, b)

    var C = null.asInstanceOf[BigInt]
    var D = null.asInstanceOf[BigInt]
    val lcmv = if (_D > _C) {
      C = BigInt(_C)
      D = BigInt(_D)
      lcm(_D, _C)
    } else {
      C = BigInt(_D)
      D = BigInt(_C)
      lcm(_C, _D)
    }


    // CでもDでも割り切れない
    // 全体から, CでもDでも割り切れる
    val v =
      (B / C) - ((A - 1) / C) + (B / D) - ((A - 1) / D) - ((B / lcmv) - ((A - 1) / lcmv))
    println(B - A + 1 - v)
  }

}