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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

T gcd(T)(T a, T b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

long numDivisors(long n, long k) {
    return n / k;
}

long calc(long a, long b, long c, long d) {

    long x = numDivisors(b, c) + numDivisors(b, d) - numDivisors(b, lcm(c, d));
    long y = numDivisors(a-1, c) + numDivisors(a-1, d) - numDivisors(a-1, lcm(c, d));


    return (b - a + 1) - (x - y);
}

void main() {
    long a, b, c, d; scan(a, b, c, d);
    writeln(calc(a, b, c, d));
}
