#include <bits/stdc++.h>
using namespace std;
long long lcm(long long a, long long b) {
  long long x;
  long long tmp;
  long long r;
  x = a * b;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return x / b;
}
long long pow_mod(long long x, long long y, long long MOD) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}
signed main() {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << ((B - A + 1) - (B / C - (A - 1) / C) - (B / D - (A - 1) / C) +
           (B / lcm(D, C) - (A - 1) / lcm(D, C)))
       << endl;
  return 0;
}
