#include<bits/stdc++.h>
using namespace std;
int main(){
  long A,B,C,D;cin>>A>>B>>C>>D;
  
  long P=C,Q=D;
  if(P<Q)swap(P,Q);
  while(P%Q!=0){
    P=P%Q;
    swap(P,Q);
  }
  Q=C*D/Q;
  long a=(A-1)/C,b=B/C,c=(A-1)/D,d=B/D,e=(A-1)/Q,f=B/Q;
  cout<<B-A+1-b+a-d+c+f-e<<endl;
}