fun main(args: Array<String>) {
    val i = readLine()!!.split(" ").map { it.toLong() }
    println(f(i[1], i[2], i[3]) - f(i[0]-1, i[2], i[3]))
}

fun f(b: Long, c: Long, d: Long): Long = b - (b/c + b/d - b/lcm(c, d))

fun gcd(a: Long, b: Long): Long = if(a < b) gcd(b, a) else if(b == 0L) a else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)
