import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val b = sc.nextLong()
    val c = sc.nextLong()
    val d = sc.nextLong()

    val z = c * d
    var x = c
    var y = d
    if (x < y) {
        val tmp = x
        x = y
        y = tmp
    }

    var r = x % y
    while (r != 0L) {
        x = y
        y = r
        r = x % y
    }
    val mm = z / y

    val all = b - a + 1
    val result = all - countMP(c, a, b) - countMP(d, a, b) + countMP(mm, a, b)
    print(result)
}

fun countMP(n: Long, min: Long, max: Long): Long {
    return (max / n) - ((min-1) / n)
}
