import java.util.*

fun xx(a: Long, b: Long): Long {
    var m = a
    var n = b
    if (m > n) {
        n = a
        m = b
    }
    var k: Long = n % m
    while (k != 0.toLong()) {
        n = m
        m = k
        k = n % m
    }
    return m
}
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val a = cin.nextLong() - 1
    val b = cin.nextLong()
    val c = cin.nextLong()
    val d = cin.nextLong()

    val c_able: Long = b/c - a/c
    val d_able: Long = b/d - a/d
    val cd: Long = c / xx(c.toLong(), d.toLong()) * d
    val cd_able: Long = b/cd - a/cd
    println(b - a - c_able - d_able + cd_able)
}