import scala.io.StdIn
import scala.math._, BigDecimal._

object Main extends App {
  val Array(a, b, c, d)  = StdIn.readLine.toString.split(" ").map(BigDecimal(_))

  def solve(a: BigDecimal, b: BigDecimal , c: BigDecimal, d: BigDecimal) : BigDecimal  = {
    val g = gcd(c.longValue(), d.longValue())
    val l = c.longValue() * d.longValue() / g


    val amod_c = ((a - 1) / c).setScale(0, RoundingMode.FLOOR)
    val amod_d = ((a - 1) / d).setScale(0, RoundingMode.FLOOR)
    val amod_cd = ((a - 1) / l).setScale(0, RoundingMode.FLOOR)

    val bmod_c = (b / c).setScale(0, RoundingMode.FLOOR)
    val bmod_d = (b / d).setScale(0, RoundingMode.FLOOR)
    val bmod_cd = (b / l).setScale(0, RoundingMode.FLOOR)


    (b - (bmod_c + bmod_d - bmod_cd)) - ((a - 1) - (amod_c + amod_d - amod_cd)) 

  }
  println(solve(a, b, c, d))

  def gcd(c: BigDecimal, d: BigDecimal): BigDecimal = {
    if (d == 0) c else gcd(d, c % d)
  }


}
  

