import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
import std.numeric;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto input = readNums!long;
  auto a = input[0], b = input[1], c = input[2], d = input[3];

  auto lcm = c * d / gcd(c, d);

  long first, last, num;
  foreach(j, k; [c, d, lcm]){
    first = a + k - a % k;
    if(a % k == 0) first -= k;

    last = b - b % k;

    num += (j == 2 ? -1 : 1) * ((last - first) / k + 1);
  }
  writeln(b - a + 1 - num);
}
