fun main(args: Array<String>) {
    var (A, B, C, D) = listOfLong()
    A -= 1
    val e = lcm(C, D)
    val ac = A / C
    val ad = A / D
    val acd = A / e
    val a = ac + ad - acd
    val bc = B / C
    val bd = B / D
    val bcd = B / e
    val b = bc + bd - bcd
    val ab = b - a
    val ans = (B - A) - ab
    println(ans)
}
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a * b / gcd(a, b)
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }