#include<bits/stdc++.h>//萬用標頭檔
using namespace std;
int main(){
long long int a,b,c,d;
cin>>a>>b>>c>>d;
c=abs(c);
d=abs(d);
if(c>d){
long long int temp=c;
c=d;
d=temp;
}
if(c==0&&d==0){
if((a>0&&b>0)||(a<0&&b<0))
cout<<0;
else cout<<1;
}
if(c==0&&d!=0){
if(a>0&&b>0){
long long int y;
if(a%d==0) y= b/d - a/d +1;
else y= b/d - a/d;
cout<<y;
}
if(a<=0&&b>=0){
long long int y;
y= b/d - a/d +1;
cout<<y;
}
if(a<0&&b<0){
long long int y;
if(b%d==0) y= b/d - a/d +1;
else y= b/d - a/d;
cout<<y;
}
}
if(c!=0&&d!=0){
if(a>=0&&b>0){
long long int x,y,z,LCM;
if(a%c==0) x= b/c - a/c +1;
else x= b/c - a/c;
if(a%d==0) y= b/d - a/d +1;
else y= b/d - a/d;
LCM=c*d/__gcd(c,d);
if(a%LCM==0) z= b/LCM - a/LCM +1;
else z= b/LCM - a/LCM;
cout<<x+y-z;
}
if(a<0&&b>=0){
long long int x,y,z,LCM;
x= b/c - a/c +1;
y= b/d - a/d +1;
LCM=c*d/__gcd(c,d);
z= b/LCM - a/LCM +1;
cout<<x+y-z;
}
if(a<0&&b<0){
long long int x,y,z,LCM;
if(b%c==0) x= b/c - a/c +1;
else x= b/c - a/c;
if(b%d==0) y= b/d - a/d +1;
else y= b/d - a/d;
LCM=c*d/__gcd(c,d);
if(b%LCM==0) z= b/LCM - a/LCM +1;
else z= b/LCM - a/LCM;
cout<<x+y-z;
}
}
}