fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val (a, b, c, d) = longList()

    val area = b - a + 1

    val cC = b / c - (a - 1) / c
    val dC = b / d - (a - 1) / d

    val cd = lcm(c, d)
    val cdC = b / cd - (a - 1) / cd
    println((area - (cC + dC - cdC)).toString())
}

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

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