import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextLong()
    val b = scanner.nextLong()
    val c = scanner.nextLong()
    val d = scanner.nextLong()
    var firstC = 0L
    var firstD = 0L
    var firstCD = 0L
    val numC:Long
    val numD:Long
    val numCD:Long
    val gcd = c*d / cal(c, d)
    var divC = a%c
    var divD = a%d
    var divCD = a%gcd
    if(divC === 0L) firstC = a
    else firstC = a+(c-divC)
    if(divD === 0L) firstD = a
    else firstD = a+(d-divD)
    if(a <= gcd) firstCD = gcd
    else if(divCD === 0L) firstCD = a
    else firstCD = a+(gcd-divCD)
    if(b < firstC) numC = 0L
    else numC = (b-firstC)/c+1L
    if(b < firstD) numD = 0L 
    else numD = (b-firstD)/d+1L
    if(b < firstCD) numCD = 0L
    else numCD = (b-firstCD)/gcd+1L
    /*println(gcd)
    println(numC)
    println(numD)
    println(numCD)*/
    val res = (b-a+1L)-(numC+numD-numCD)
    println(res)
}

fun cal(x:Long, y:Long): Long{
    var x2 = x;
    var y2 = y;
    if(x2 < y2) return cal(y2, x2);
    if(y2 === 0L) return x2;
    return cal(y2, x2 % y2);
}