#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main() {
    LL a,b,c,d;
    cin>>a>>b>>c>>d;
    LL lcm=c*d/gcd(c,d);
    a--;
    LL l = a/c+a/d-a/lcm;
    LL r = b/c+b/d-b/lcm;
    cout << (b - r) - (a - l) <<endl; 
}