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

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

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

void main() {
  auto input = readln.split.to!(ulong[]);
  ulong A = input[0], B = input[1], C = input[2], D = input[3];

  ulong f(ulong n) {
    return (B/n)-((A-1)/n);
  }

  ulong num = f(C) + f(D) - f(lcm(C, D));
  (B - A + 1 - num).writeln;
}
