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