fun main(args: Array<String>) {
    val (a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }

    val gcd = calcGcd(c, d)

    val bX = b - (b / c) - (b / d) + (b / ((c * d) / gcd))

    val aX = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / ((c * d) / gcd))

    println(bX - aX)
}

fun calcGcd(c: Long, d: Long): Long {
    return if (d == 0.toLong()) {
        c
    } else {
        calcGcd(d, c % d)
    }
}
