fun main(args : Array<String>) {
    val (A, B, C, D) = readLine()!!.split(" ").map { it.toLong() }

    val LCM = lcm(C, D)
    val allNumsBetweenRange = B - A + 1
    val cNums = countHowManyNumbersMultipledBy(C, A, B)
    val dNums = countHowManyNumbersMultipledBy(D, A, B)
    val lcmNums = countHowManyNumbersMultipledBy(LCM, A, B)
    println(allNumsBetweenRange - (cNums + dNums) + lcmNums)
}


// from, to inlucsive
fun countHowManyNumbersMultipledBy(multiplier: Long, from: Long, to: Long) : Long {
    val supplement = if (from.mod(multiplier) == 0L) 1 else 0
    return to / multiplier - from / multiplier + supplement
}


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


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