function main(input) {
  input=input.trim();
  const a = parseInt(input.split(" ")[0], 10);
  const b = parseInt(input.split(" ")[1], 10);
  const c = parseInt(input.split(" ")[2], 10);
  const d = parseInt(input.split(" ")[3], 10);

  var baisuu=function(n){
    var A
    if(a%n==0){
      A=a/n
    }else{
      A=Math.floor(a/n)+1;
    }
    var B=Math.floor(b/n);
    return B-A+1
  }

  function gcd(a, b){
    if(b != 0)
        return gcd(b, a%b);
    else
        return a;
  }

  function lcm(a,b){
    return a * b / gcd(a, b);
  }
  console.log(b-a+1-(baisuu(c)+baisuu(d)-baisuu(lcm(c,d))));
  
}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));
