import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

long gcd(long x, long y) {
    return x % y ? gcd(y, x%y) : y;
}

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

    long count(long x) {
        if (x == 0) return 0L;
        return x - x/c - x/d + x / (c / gcd(c,d) * d);
    }
    long x = count(b);
    long y = count(a - 1);
    debug writeln(x, " ", y);
    writeln(x - y);
}
