fun main(args: Array<String>) = println(run {
    val (a,b,c,d) = readLine()!!.split(" ").map { it.toLong() }
    fun count(x: Long) = x - x/c - x/d + x/((c*d)/gcd(c,d))
    count(b)-count(a-1)
})

tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
