import java.util.*
import java.math.*

fun main(args: Array<String>) {

    var (A,B,C,D) = readLine()!!.split(" ").map { it.toLong() }
//    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

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

    A--
    var ac = A/C
    var ad = A/D
    var acd = A/(C/gcd(C,D)*D)
    var bc = B/C
    var bd = B/D
    var bcd = B/(C/gcd(C,D)*D)

    println(B-A - (bc+bd-bcd -(ac+ad-acd)))

//    println("%.9f".format(ans))
}
