
object Main extends App {
  import scala.io.StdIn._
  val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toLong)
  val lower = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm(c, d)
  val upper = b - b / c - b / d + b / lcm(c, d)
  println(upper - lower)
  def gcd(a: Long, b: Long): Long = {
    b match {
      case 0 => a
      case _ => gcd(b, a % b)
    }
  }
  def lcm(a: Long, b: Long): Long = {
    a / gcd(a, b) * b
  }
}
