import scala.io.StdIn


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

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


    val amod_c = (a / c).floor
    val amod_d = (a / d).floor
    val amod_cd = (a / l).floor

    val bmod_c = (b / c).floor
    val bmod_d = (b / d).floor
    val bmod_cd = (b / l).floor

    if (a % c == 0 || a % d == 0) ad = 0


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

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

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


}
  

