#include typedef long long ll; #define FOR(i,l,r) for (int i=l;i<=r;i++) #define FOD(i,r,l) for (int i=r;i>=l;i--) #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; int BCNN(int a, int b) { int result = __gcd(a, b); return a * b / result; } int main() { freopen("countnum.inp","r",stdin); freopen("countnum.out","w",stdout); fast; ll L,R,a,b; cin>>L>>R>>a>>b; int t = BCNN(a,b); ll s, sa , sb, sab; s = R - L + 1; sa = s/a; sb = s/b; sab = (R / t) - ((L-1) / t); cout<< s - (sa + sb - sab); }