fun main() {
    fun gcd(c:Long, d:Long):Long{
        if (d>c){return gcd(d,c)}
        if (c%d==0L){return d}
        return gcd(d, c%d)
    }
    val (a,b,c,d)= readLine()!!.split(" ").map { it.toLong() }
    val c_div=b/c-(a-1)/c
    val d_div=b/d-(a-1)/d
    val lcm=c*d/gcd(c,d)
    val lcm_div=b/lcm-(a-1)/lcm


//    println(c_div)
//    println(d_div)
//    println(lcm_div)
    println(b-a+lcm_div-c_div-d_div+1)
}