#include <bits/stdc++.h>
using namespace std;

long long GCD(long long a, long long b){
	if(b==0) return a;
  else return GCD(b,a%b);
}

int main(){
  
  long A,B,C,D,E,aa,bb;
  cin >>A>>B>>C>>D;
  E=C*D/GCD(C,D);
  aa=B/C-(A-1)/C+B/D-(A-1)/D;
  bb=B/E-(A-1)/E;
  
  cout << B-A+1-aa+bb << endl;
  
}