#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
LL a,b,c,d,t;
LL gcd(LL x,LL y){
	if(x==0)return y;
	return gcd(y%x,x);
}
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);t=c*d/gcd(c,d);
	printf("%lld\n",b-a+1-(b/c-(a-1)/c+b/d-(a-1)/d-(b/t-(a-1)/t)));
}