#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y)
{
	return x==0?y:gcd(y%x,x);
}
long long a,b,c,d;
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long lcm=c*d/gcd(c,d);
	printf("%lld",(b-a+1)-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/lcm-(a-1)/lcm));
	return 0;
}