#import <Foundation/Foundation.h>
typedef long long Int;
Int gcd(Int a, Int b){
	Int M = MAX(a, b);
	Int m = MIN(a, b);
	while (YES) {
		Int r = M % m;
		if (r==0) break;
		M = m;
		m = r;
	}
	return m;
}
Int lcm(Int a, Int b){
	return a/gcd(a,b)*b;
}
Int f(Int a, Int b, Int m){
	return b/m-(a-1)/m;
}
int main() {
	Int a,b,c,d;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	printf("%lld",(b-a+1)-f(a,b,c)-f(a,b,d)+f(a,b,lcm(c,d)));
}