import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val a = input.split(" ").head.toLong - 1
    val b = input.split(" ").tail.head.toLong
    val c = input.split(" ").tail.tail.head.toLong
    val d = input.split(" ").tail.tail.tail.head.toLong
    val nc = b / c - a / c
    val nd = b / d - a / d
    val ncd = b / lcm(c, d) - a / lcm(c, d)

    (b - a - (nc + nd - ncd)).toString
  }

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

  val tests=List(
    """4 9 2 3""".stripMargin -> """2
                                   |""".stripMargin,
    """10 40 6 8""".stripMargin -> """23""".stripMargin,
    """314159265358979323 846264338327950288 419716939 937510582""" -> "532105071133627368"
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}