fun main(args: Array<String>) {
    val (A, B, C, D) = readLine()!!.split(' ').map { it.toLong() }
    val cd = lcm(C, D)
    val aDIVc = A.div(C)
    val aDIVd = A.div(D)
    val bDIVc = B.div(C)
    val bDIVd = B.div(D)
    val aDIVcd = A.div(cd)
    val bDIVcd = B.div(cd)
    var res = (B - bDIVc - bDIVd + bDIVcd) - (A - aDIVc - aDIVd + aDIVcd)
    if (A % C != 0L && A % D != 0L) {
        res = res.inc()
    }
    println(res)
}

private fun gcd(m: Long, n: Long): Long {
    if (m < n) return gcd(n, m)
    return if (n == 0L) m else gcd(n, m % n)
}

private fun lcm(m: Long, n: Long): Long {
    return m * n / gcd(m, n)
}
