#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;


long long int gcd(int a, int b)
{
  if (a < b)
  {
    int tmp;
    tmp = a;
    a = b;
    b = tmp;
  }

  int r = a % b;
  while (r != 0)
  {
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}


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



void anti_division()
{
  long long int a, b;
  int c, d;
  cin >> a >> b >> c >> d;

  --a;
  long long int a_cnt = a - a / c - a / d + a / lcm(c, d);
  long long int b_cnt = b - b / c - b / d + b / lcm(c, d);

  cout << b_cnt - a_cnt << "\n";
}


void devide_the_problems()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];

  sort(d.begin(), d.end());

  cout << d[n / 2] - d[n / 2 - 1] << "\n";
}


void remainder_minimization()
{
  long long int l, r;
  cin >> l >> r;

  if (r - l >= 2019)
  {
    cout << 0 << "\n";
    return;
  }

  int v_min = 2019;
  for (long long int i = l; i <= r - 1; ++i)
  {
    for (long long int j = l + 1; j <= r; ++j)
    {
      int tmp = (i * j) % 2019;
      if (v_min > tmp) v_min = tmp;
    }
  }

  cout << v_min << "\n";
}


void exeption_handling()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  vector<int> a_copy(a.size());
  for (int i = 0; i < a.size(); ++i) a_copy[i] = a[i];
  sort(a_copy.begin(), a_copy.end(),greater<int>());
  int v_max = a_copy[0], v_max_second = a_copy[1];

  for (int i = 0; i < n; ++i)
  {
    if (a[i] == v_max) cout << v_max_second << "\n";
    else cout << v_max << "\n";
  }
}


//skip
void city_savers()
{
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n);
  for (int i = 0; i < n + 1; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];


}


void build_stairs()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];

  for (int i = n - 1; i > 0; --i)
  {
    if (h[i - 1] - h[i] > 1)
    {
      cout << "No" << "\n";
      return;
    }
    else if (h[i - 1] - h[i] == 1)
    {
      --h[i - 1];
    }
  }
  cout << "Yes" << "\n";
}


void green_bin()
{
  int n;
  cin >> n;
  map<string, int> S;
  for (int i = 0; i < n; ++i) 
  {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    S[s]++;
  }

  long long int ana_num = 0;
  for (auto value : S)
    for (int cnt = value.second - 1; cnt > 0; --cnt) 
      ana_num += cnt;
 
  cout << ana_num << "\n";
}


void alchemist()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  sort(v.begin(), v.end());

  double v_sum = v[0];
  for (int i = 1; i < n; ++i) v_sum = (v_sum + v[i]) / 2;

  cout << v_sum << "\n";
}


void lower_atc()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];


  int tmp = 0, v_max = 0;
  for (int i = 0; i < n; ++i)
  {
    if ((i != n - 1) && h[i] >= h[i + 1]) ++tmp;
    else
    {
      v_max = max(v_max, tmp);
      tmp = 0;
    }
  }

  cout << v_max << "\n";
}


void maximal_value()
{
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> b[i];

  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    if (i == 0)          a[i] = b[i];
    else if (i == n - 1) a[i] = b[i - 1];
    else                 a[i] = min(b[i - 1], b[i]);
  }

  cout << accumulate(a.begin(), a.end(), 0) << "\n";
}


int main()
{
  anti_division();
  //devide_the_problems();
  //remainder_minimization();
  //exeption_handling();
  //city_savers();
  //build_stairs();
  //green_bin();
  //alchemist();
  //lower_atc();
  //maximal_value();
}


Measured memory_bytes: 256