import std.stdio, std.string, std.array, std.conv, std.algorithm;

long lcm(long x, long y) {
    import std.numeric;
    return x * y / gcd(x, y);
}

void main() {
    long[] tmp = readln.split.to!(long[]);
    long a = tmp[0] - 1, b = tmp[1], c = tmp[2], d = tmp[3];
    long l = lcm(c, d);
    long n = b - b / c - b / d + b / l;
    long m = a - a / c - a / d + a / l;
    writeln(n - m);
}