fun main(args: Array<String>) {

    val calc = { N: Long, L: Long, U: Long ->
        //        println(N)
//        println("($N - ($N / $L + $N / $U - $N / ($L * $U)))")
        (N - (N / L + N / U - N / lcm(L, U)))
    }

    val (A, B, C, D) = readLine()!!.split(" ").map(String::toLong)


//    println(calc(B, C, D))
//    println(calc(A - 1, C, D))
    println(calc(B, C, D) - calc(A - 1, C, D))
}

fun lcm(a: Long, b: Long): Long{
    return a * b / gcd(a, b)
}

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