import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toLong()
        val B = sc.next().toLong()
        val C = sc.next().toLong()
        val D = sc.next().toLong()
        val E = lcm(C, D)
        val b = (B / C + B / D - B / E)
        val a = ((A - 1) / C + (A - 1) / D - (A - 1) / E)
        val ans = (B - A + 1) - (b - a)
        pw.println(ans)

    }
}
