import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c, d = sc.nextLong

  val lc = lcm(c, d)
  val total = b / c + b / d - b / lc
  val part = a / c + a / d - a / lc
  val ans = b - a - (total - part) + (if (a % c != 0 && a % d != 0) 1 else 0)

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b
}