import std.stdio, std.array, std.conv, std.typecons, std.algorithm, std.numeric, std.bigint;

T diff(T)(const T a, const T b) { return a > b ? a - b : b - a; }
T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void main() {
    const ip = readToArray!(ulong);
    const auto a = ip[0], b = ip[1], c = ip[2], d = ip[3];
    const auto all_cnt = b - a + 1;

    if (c == 1 || d == 1) {
        writeln(all_cnt);
    } else { // c != 1 && d != 1
        ulong lcm;
        {
            BigInt abig = c;
            BigInt bbig = d;
            BigInt lcmbig = c * d / gcd(c,d);
            lcm = lcmbig.to!(ulong);
        }
        //writefln("%d %d %d\n", c, d, lcm);
        ulong c_div = b/c - a/c;
        ulong d_div = b/d - a/d;
        ulong lcm_div = b/lcm - a/lcm;
        //writefln("%d %d %d\n", c_div, d_div, lcm_div);
        writeln(all_cnt-(c_div+d_div-lcm_div));
    }
}
