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(0);
    } else { // c != 1 && d != 1
        ulong lcm = c*d/gcd(c, d);
        //writefln("!!%d %d %d\n", c, d, lcm);
        ulong c_div = b/c - (a-1)/c;
        ulong d_div = b/d - (a-1)/d;
        ulong lcm_div = b/lcm - (a-1)/lcm;
        //writefln("!!%d %d %d\n", c_div, d_div, lcm_div);
        writeln(all_cnt-(c_div+d_div-lcm_div));
    }
}
