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