fun main(args: Array<String>) {
    val (min, max, numC, numD) = readLine()!!.split(" ").map { it.toLong() }
    val leastCommon = (numC * numD) / gcd(numC, numD)
    val total = 1 + max - min

    print(total - (countSet(min, max, numC) + countSet(min, max, numD) - countSet(min, max, leastCommon)))
}

fun countSet(min: Long, max: Long, num: Long): Long {
    val tempTotal = max / num
    val outside = (min - 1) / num

    return tempTotal - outside
}

fun gcd(a: Long, b: Long): Long {
    return if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
}
