// inputに入力データ全体が入る
function Main(input) {
  line = input.split(" ");
  var A = +line[0];
  var B = +line[1];
  var C = +line[2];
  var D = +line[3];
  var count = 0;
  
  var totalPossible = B-A+1;
  var startPointC = Math.ceil(A/C);
  var endPointC = Math.floor(B/C);
  var startPointD = Math.ceil(A/D);
  var endPointD = Math.floor(B/D);
  
  
  function findLCM(x,y){
    // gcd :: Integral a => a -> a -> a
  var gcd = (x, y) => {
        var _gcd = (a, b) => (b === 0 ? a : _gcd(b, a % b)),
            abs = Math.abs;
        return _gcd(abs(x), abs(y));
    }
 
    // lcm :: Integral a => a -> a -> a
  var lcm = (x, y) =>
        x === 0 || y === 0 ? 0 : Math.abs(Math.floor(x / gcd(x, y)) * y);
 
    // TEST
    return lcm(x, y);
  }
  
    
  var LCM = findLCM(C, D);
  var startPointCD = Math.ceil(A/LCM);
  var endPointCD = Math.floor(B/LCM);
 
  
  //console.log(totalPossible, startPointC, endPointC, startPointD, endPointD);
  
  count = count + endPointC - startPointC + 1 +endPointD - startPointD + 1;
  
  count = count - (endPointCD - startPointCD +1);
    
  console.log(totalPossible - count);
  
}
  
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
