#include<bits/stdc++.h>
using namespace std;
long gcd(long c,long d){
  if(c%d==0)return d;
  return gcd(d,c%d);
}
int main(){
  long a,b,c,d;cin>>a>>b>>c>>d;
  long e=c*d/gcd(c,d);
  cout<< (b-a+1)-((b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/e-(a-1)/e));
  
}