import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val Array(a, b, c, d) = StdIn.readLine().split(' ').map(_.toLong)
    println(solve(a, b, c, d))
  }

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

  def count(a: Long, c: Long, d: Long): Long = {
    a - a / c - a / d + a / lcm(c, d)
  }

  def lcm(x: Long, y: Long): Long = {
    x * y / gcd(x, y)
  }

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

}
