import java.io.BufferedInputStream



// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    fun iterateTokens(): Iterator<String> {
        val reader = BufferedInputStream(System.`in`).bufferedReader()
        val iterator = reader.lineSequence()
                .map { it.split(" ") }
                .reduce { left, right -> left + right }
                .iterator()
        return iterator
    }
    val tokens = iterateTokens()
    val A = tokens.next().toLong()
    val B = tokens.next().toLong()
    val C = tokens.next().toLong()
    val D = tokens.next().toLong()
    solve(A, B, C, D)
}

fun <T : Comparable<T>> maxOf(a: T, b: T): T = if (a > b) a else b
fun <T : Comparable<T>> minOf(a: T, b: T): T = if (a < b) a else b

fun gcd(a: Long, b: Long): Long{
    fun _gcd(m: Long, n: Long): Long = if (m == 0L) n else _gcd(n % m, m)
    val m = minOf(a, b)
    val n = maxOf(a, b)
    return _gcd(m, n)
}

fun divsCount(start: Long, end: Long, mod: Long): Long{
    return (end / mod) - (start - 1) / mod
}

fun solve(A: Long, B: Long, C: Long, D: Long){
    val ans = B - A + 1L - divsCount(A, B, C) - divsCount(A, B, D) + divsCount(A, B, (C*D)/gcd(C, D))
    println(ans)
    return
}

