#include<bits/stdc++.h>
using namespace std;
long long gcd(long long l,long long w){
	if(w==0)return l;
	return gcd(w,l%w);
}
long long a,b,c,d,e,f;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	e=c/gcd(c,d)*d;
	f=b/c+b/d-b/e-(a-1)/c-(a-1)/d+(a-1)/e;
	printf("%lld",b-a+1-f);
}