import scala.io.StdIn

object Main extends App {
  val inputs = StdIn.readLine().split(" ").map(_.toLong)
  val A = inputs(0)
  val B = inputs(1)
  val C = inputs(2)
  val D = inputs(3)

  def gcm(m: Long, n: Long, divisor: Long = 2, accum: Long = 1): Long = {
    if (m < divisor) {
      D / accum * C
    } else {
      if (m % divisor == 0 && n % divisor == 0) {
        gcm(m / divisor, n / divisor, divisor, accum * divisor)
      } else {
        gcm(m, n, divisor + 1, accum)
      }
    }
  }

  val div = B - A
  val onlyC = div / C + 1
  val onlyD = div / D + 1
  val both = div / gcm(C, D) + 1

  val result = (B - A + 1) - (onlyC + onlyD - both)
  println(result)
}