#include<iostream>
#include<cstdio>

using namespace std;

int gcd(int m,int n)
{
  return n? gcd(n, m%n) : m;
}

int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    int e=c/gcd(c,d);
    e*=d;
    long long ans=(b-a+1)-(b/c+b/d-b/e)+((a-1)/c+(a-1)/d-(a-1)/e);
    cout<<ans<<endl;
    return 0;
}