object Main extends App {
  var get = readLine.split(" ")
  var a = get(0).toLong
  var b = get(1).toLong
  var c = get(2).toLong
  var d = get(3).toLong
  var e = b - a
  var sum = 0l
  var i = 0
  
  def gcd(a: Long, e: Long, c: Long, d:Long,sum: Long):Unit = {
    var sum1=0l
    if(0!=e){
      if(a + i%c!=0)if(a + i%d!=0) sum1 = sum + 1
    	gcd(a,e-1,c,d,sum1)
    } else {
  		println(sum1)
    }
  }
  gcd(a,e,c,d,0)
}