import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
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 lcm(T)(T a, T b) {
    return a * (b / gcd(a, b));
}

long calc(long a, long b, long c, long d) {
    // [1, n] で k で割り切れない数の個数
    long f(long n, long k) {
        return n - (n / k);
    }

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

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