#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

long long gcd(long long a,long long b)
{
    return b==0?a:gcd(b,a%b);
}

long long lms(long long  a,long long  b)
{
    return (a*b)/gcd(a,b);
}

int main()
{
    long long a,b;
    long long c,d;
    long long nc=0;
    //long long i,j;
    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){
    long long Lms=lms(c,d);
    if(a%c==0) nc++;
    if(b%c==0) nc++;
    if(a%d==0) nc++;
    if(b%d==0) nc++;
    nc+=(b/c-a/c-1);
    nc+=(b/d-a/d-1);
    if(a%Lms==0) nc--;
    if(b%Lms==0) nc--;
    nc-=(b/Lms-a/Lms-1);
    printf("%lld",b-a+1-nc);}
}
