import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long a, b, c, d;
    scan(a, b, c, d);
    long lcm = c * d / gcd(c, d);
    // writeln(lcm);
    long c_cnt = b / c - (a - 1) / c;
    long d_cnt = b / d - (a - 1) / d;
    long lcm_cnt = b / lcm - (a - 1) / lcm;
    // writeln(c_cnt);
    // writeln(d_cnt);
    // writeln(lcm_cnt);
    writeln((b - a + 1) - (c_cnt + d_cnt - lcm_cnt));

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}
