#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,c,d;
ll gcd(ll x,ll y){
    return y==0?x:gcd(y,x%y);
}
int main(){
	cin>>a>>b>>c>>d;
	ll o=c/gcd(c,d)*d;
	ll d1=b/c-(a-1)/c,d2=b/d-(a-1)/d,d3=b/o-(a-1)/o;
	ll all=d1+d2-d3;
	cout<<(b-a+1)-all;
	
}