fun main(args: Array<String>) {
    val (a, b, c, d) = readLine()!!.split(' ').map(String::toLong)
    val po1 = b / c - (a - 1) / c
    val po2 = b / d - (a - 1) / d
    fun gcd(x: Long, y: Long): Long {
        val (y1, x1) = listOf(x, y).sorted()
        val po = x1 % y1
        return if (po == 0L) y1 else gcd(y1, po)
    }
    fun lcm(x: Long, y: Long): Long {
        val g = gcd(x, y)
        return g * (x / g) * (y / g)
    }
    val meu = lcm(c, d)
    val po3 = b / meu - (a - 1) / meu
    println((b - a + 1) - po1 - po2 + po3)
}
