import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.next().toLong()
    val b = sc.next().toLong()
    val c = sc.next().toLong()
    val d = sc.next().toLong()

    println(abc131c(a, b, c, d))
}

private fun abc131c(a: Long, b: Long, c: Long, d: Long): Long {
    var l = lcm(c, d)

    var ans = b - a + 1
    ans -= (b / c) + (b / d) - (b / l)
    ans += ((a - 1) / c) + ((a - 1) / d) - ((a - 1) / l)

    return ans
}

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

private fun gcd(a: Long, b: Long): Long {
    if (b > 0) {
        return gcd(b, a % b)
    }
    return a
}