"use strict";
    
const main = arg => {
  let Nums = arg.split(" ");
  let Min = Nums[0]*1;
  let Max = Nums[1]*1;
  let div1 = Nums[2]*1;
  let div2 = Nums[3]*1;
  let lcmNum = lcm(div1,div2);
  let ans = 0;
  let diff = (Max - Min)*1;
  let x = Math.floor(diff / div1);
  let y = Math.floor(diff / div2);
  let z = Math.floor(diff / lcmNum);
  
  console.log(diff - x - y + z);
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

// もらいもののアルゴリズム
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}