import java.lang.Math.abs

fun main(args: Array<String>) {
  val (a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
  val dividableCNum = b / c - (a - 1) / c
  val dividableDNum = b / d - (a - 1) / d
  val dividableCDNum = b / lcm(c, d) - (a - 1) / lcm(c, d)
  println(b - a + 1 - (dividableCNum + dividableDNum - dividableCDNum))
}

fun gcd(a: Long, b: Long): Long = if(a < b) gcd(b, a) else if(b == 0L) a else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)