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] で x で割り切れる数の個数
    long f(long n, long x) {
        return n / x;
    }

    // 区間 [1, n] で x or y で割り切れる数の個数
    long g(long n, long x, long y) {
        return f(n, x) + f(n, y) - f(n, lcm(x, y));
    }

    // 区間 [1, n] で x or y で割り切れない数の個数
    long h(long n, long x, long y) {
        return n - g(n, x, y);
    }

    return h(b, c, d) - h(a - 1, c, d);
}

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