fun main(args:Array<String>){
    val line = readLine()!!.split(" ").map{it.toLong()}
    val a = line[0]
    val b = line[1]
    val c = line[2]
    val d = line[3]
    val e = a-1
    val lcm = c*d/gcd(c,d)
    val result = b-a+1L-((b/c + b/d - b/lcm)-(e/c + e/d - e/lcm))
    println(result)
}
fun gcd(c:Long,d:Long):Long{
    return if(d>0)gcd(d,c%d)else c
}