
fun main(arr:Array<String>) {
    val (a,b,c,d) = readLine()!!.split(" ").map { it.toLong() }
    val ans = (b-a+1) - getCount(a,b,c) - getCount(a,b,d) + getCount(a,b,getKoubai(c,d))
    println(ans)
}

fun getKouyaku(num1:Long, num2:Long):Long {
    if(num1 % num2 == 0L) {
        return  num2
    }
    return getKouyaku(num2, num1%num2)
}

fun getKoubai(num1:Long, num2:Long):Long {
    val kouyaku = getKouyaku(num1, num2)
    return kouyaku * (num1/kouyaku) * (num2/kouyaku)
}

fun getCount(a:Long, b:Long, num:Long):Long {
    var posMin = (a/num)*num
    if(posMin < a) {
        posMin+=num
    }
    val posMax = (b / num)*num
    if(posMin > posMax) {
        return 0
    }
    return ((posMax - posMin) / num) + 1
}
