"use strict"
function main(arg) {
    arg = arg.trim().split("\n")[0].split(" ").map(Number)
    // let A, B, C, D
    // [A, B, C, D] = arg
    let A = arg[0]
    let B = arg[1]
    let C = arg[2]
    let D = arg[3]
    let M = lcm(C, D)
    let cStart = A
    let dStart = A
    let mStart = A
    let cEnd = B
    let dEnd = B
    let mEnd = B
    if (A % C !== 0) {
        cStart = A + C - (A % C)
    }
    if (A % D !== 0) {
        dStart = A + D - (A % D)
    }
    if (A % M !== 0) {
        mStart = A + M - (A % M)
    }
    if (B % C !== 0) {
        cEnd = B - (B % C)
    }
    if (B % D !== 0) {
        dEnd = B - (B % D)
    }
    if (B % M !== 0) {
        mEnd = B - (B % M)
    }
    let cAns = (cEnd - cStart) / C + 1
    let dAns = (dEnd - dStart) / D + 1
    let mAns = (mEnd - mStart) / M + 1

    // console.log([C, D, M])
    // console.log([cStart, dStart, mStart])
    // console.log([cEnd, dEnd, mEnd])
    // console.log([cAns, dAns, mAns])
    
    var tAns = cAns + dAns - mAns
    console.log(B - A - tAns + 1)


    // var _cAns = 0
    // var _dAns = 0
    // var _mAns = 0
    // var _tmp = 0
    // for (var i = A; i <= B; i++) {
    //     if (i % C == 0) {
    //         _cAns++
    //     }
    //     if (i % D == 0) {
    //         _dAns++
    //     }
    //     if (i % M == 0) {
    //         _mAns++
    //     }
    //     if (i % C !== 0 && i % D !== 0) {
    //         _tmp++
    //     }
    // }
    // console.log([_cAns, _dAns, _mAns])
    // console.log(_tmp)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}