"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const euc = (x, y) => {
    if (x == 0) return y
    if (y == 0) return x
    if (x > y) {
        return euc(x % y, y)
    } else {
        return euc(y % x, x)
    }
}
const Main = () => {
    const [A, B, C, D] = next().split(" ").map(el => BigInt(el))
    //B
    let bc = B / C
    let bd = B / D
    let min = C * D / euc(C, D)
    let bcd = B / min
    let b = B - bc - bd + bcd
    //A
    let ac = (A-1n) / C
    let ad = (A-1n) / D
    let acd = (A-1n) / min
    let a = A-1n - ac - ad + acd

    console.log(String(b-a))
}
Main()
