import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  long a, b, c, d;
  
  readf("%s %s %s %s\n", &a, &b, &c, &d);

  auto cnt = b - a + 1;

  auto t = new long[](3);
  t[0] = c;
  t[1] = d;
  t[2] = c * d;
  auto tn = new long[](3);

  foreach (j; 0..3) {
    auto x1 = a % t[j];
    if (x1 == 0) {
      x1 = t[j];
    }
    auto x = a + t[j] - x1;
    if (x > b) {
      x = 0;
    }

    auto y1 = b % t[j];
    if (y1 == 0) {
      y1 = t[j];
    }
    auto y = b - t[j] + y1;
    if (y < a) {
      y = 0;
    }
    
    tn[j] = (y - x) / t[j] + 1;
  }

  cnt -= tn[0] + tn[1] - tn[2];

  cnt.writeln;
}
