tailrec 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 { it.toLong() }
    val bc = b/c
    val bd = b/d
    val ac = (a-1)/c
    val ad = (a-1)/d
    val bcd = b/( c/gcd(c,d)*d )
    val acd = (a-1)/( c/gcd(c,d)*d )
    println(b-(a-1) -(bc-ac) -(bd-ad) +(bcd-acd))
}