import scala.io.StdIn.readLine

object Main extends App {

  readLine.trim.split(' ').map(_.toLong) match {
    case Array(a, b, c, d) =>
      val toB = b - b / c - b / d + b / lcm(c, d)
      val untilA = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm(c, d)
      println(toB - untilA)
    case _ => ???
  }

  def lcm(a: Long, b: Long): Long = {
    a / gcd(a, b) * b
  }
  def gcd(a: Long, b: Long): Long = {
    b match {
      case 0 => a
      case _ => gcd(b, a % b)
    }
  }
}