fun main(args: Array<String>) {
    var (a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
    val ran = b - a + 1
    if (c == 1L || d == 1L) {
        println(0)
        return
    }
    val cc = b / c - (a - 1) / c
    val dd = b / d - (a - 1) / d
    val cd = c * d / gcd(c, d)
    val ccdd = b / cd - (a - 1) / cd
    println(ran - cc - dd + ccdd)
}

fun gcd(x: Long, y: Long): Long {
    if (x < y) return gcd(y, x)
    if (y == 0L) return x
    return gcd(y, x % y)
}