import java.util.*

fun main(args:Array<String>){
    val (a,b,c,d) = readLine()!!.split(" ").map{it.toLong()}
    val k = b / c + b / d - b / lcm(c,d) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm(c,d))
    println(b - a + 1 - k)
}

fun gcd(a : Long, b : Long) : Long{
    if(a % b == 0L) return b
    return gcd(b, a % b)
}

fun lcm(a : Long, b : Long) : Long{
    return a / gcd(a, b) * b
}