import std.stdio, std.string, std.conv, std.algorithm, std.range, std.array, std.typecons, std.math, std.numeric;

long lcm(long a, long b) {
    return a * b / gcd(a, b);
}

void main() {
    long a,b,c,d;
    readf("%d %d %d %d\n", &a, &b, &c, &d);
    long e = lcm(c, d);

    long a1 = a + (c - a % c) % c;
    long b1 = b - b % c;
    // writefln("(%d, %d) -> %d", a1, b1, (b1 - a1) / c + 1);

    long a2 = a + (d - a % d) % d;
    long b2 = b - b % d;
    // writefln("(%d, %d) -> %d", a2, b2, (b2 - a2) / d + 1);

    long a3 = a + (e - a % e) % e;
    long b3 = b - b % e;
    // writefln("(%d, %d) -> %d", a3, b3, (b3 - a3) / e + 1);

    long ans = (b - a) + 1;
    ans -= (b1 - a1) / c + 1;
    ans -= (b2 - a2) / d + 1;
    ans += (b3 < a3) ? 0 : ((b3 - a3) / e + 1 );

    writeln(ans);


}
