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;

    ulong lcm = c*d/gcd(c, d);
    //writefln("!!%d %d %d\n", c, d, lcm);
    ulong c_div = (b-a+1)/c;
    ulong d_div = (b-a+1)/d;
    ulong lcm_div = (b-a+1)/lcm;
    //writefln("!!%d %d %d\n", c_div, d_div, lcm_div);
    writeln(all_cnt-(c_div+d_div-lcm_div));
}
