import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val a = argList.nextLong()
    val b = argList.nextLong()
    val c = argList.nextLong()
    val d = argList.nextLong()
    val executor = AntiDivision()
    println(executor.execute(a, b, c, d))

}

class AntiDivision {
    fun execute(a: Long, b: Long, c: Long, d:Long ): Long {

        val allAmount = b - a + 1
        val divAmountByC = (b / c) - ((a - 1) / c)
        val divAmountByD = (b / d) - ((a - 1) / d)
        val gcd = calcGcd(c, d)
        val lcm = (c * d) / gcd
        val divAmountBoth = (b / lcm -  ((a - 1) / lcm))
        
        return allAmount - (divAmountByC + divAmountByD - divAmountBoth)
    }
    private tailrec fun calcGcd(a: Long, b: Long): Long =
            if ( b == 0L ) a
            else calcGcd(b, a % b)
}