#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll gcd(ll a,ll b) {
  return (b? gcd(b,a%b):a);
}

int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll n_c=b/c-(a-1)/c;
  ll n_d=b/d-(a-1)/d;
  ll l=c/gcd(c,d)*d;
  ll n_cd=b/l-(a-1)/l;
  cout<<b-a+1-(n_c+n_d-n_cd)<<endl;
  return 0;
}

