const main = input => {
    input = input[0].split(' '),a = BigInt(input[0]),b = BigInt(input[1]),c = BigInt(input[2]),d = BigInt(input[3]);
    const euclid = (x,y) => {
        while(1) {
            if (x == 0n) return y;
            if (y == 0n) return x;
            if (x>y) x = x%y;
            else if (y>x) y = y%x; 
            else return x;            
        }
    };
    let l = BigInt(c*d/euclid(c,d));
    // console.log(l);
    let asum = BigInt(a-BigInt(1)-(a-BigInt(1))/c-(a-BigInt(1))/d+(a-BigInt(1))/l);
    let bsum = BigInt(b-b/c-b/d+b/l);
    // console.log(bsum-asum);
    let ans = (bsum-asum)+'';
    console.log(ans);
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));