fun main(args: Array<String>) {
    var (A, B, C, D) = listOfLong()
    val E = lcm(C , D)
    fun f(x: Long): Long {
        val a = x / C
        val b = x / D
        val c = x / E
        return x - (a + b - c)
    }
    val ans = f(B) - f(A - 1)
    println("${ans}")
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a * b / gcd(a, b)
