import java.util.*
fun gcd(a: Long, b: Long): Long = if(b == 0L) {a} else {gcd(b, a % b)}

fun main(args:Array<String>) {
    val (A,B,C,D) = readLine()!!.split(" ").map(String::toLong)
    val times_c = B / C - A / C + (if(A % C == 0L){1L} else {0L})
    // println("times_c: ${times_c}")
    val times_d = B / D - A / D + (if(A % D == 0L){1L} else {0L})
    // println("times_d: ${times_d}")
    val lcm_cd =  (C / gcd(C,D)) * D
    // println("lcm_cd: ${lcm_cd}")
    val times_common = B / lcm_cd - A / lcm_cd + (if(A % lcm_cd == 0L){1L} else {0L})
    // println("times_common: ${times_common}")

    (B - A + 1 - times_c - times_d + times_common).run(::println) 

}