//  [javascript]
var natural={};

natural.successor=function(a){
    var ret=a.split(' ');
    for(var i=ret.length-1;i>=0;i--){
        if(ret[i]==='9'){
            ret[i]=0;
        }else{
            ret[i]=(ret[i]-0)+1+'';
            break;
        }
        if(i===0){
            ret.unshift('1');
        }
    }
    return ret.join('');
}

natural.add=function(...nums){//あまりにも多いnumsは扱えません
    var array=[];
    var max=0;
    nums.forEach(e=>{
        if(max<e.length){
            max=e.length;
        }
    });
    nums.forEach(e=>{
        array.push('0'.repeat(max-e.length)+e);
    });
    var temp;
    var ret='';
    var c=0;//繰り上がり
    for(var i=max-1;i>=0;i--){
        temp=c;
        array.forEach(e=>{
            temp+=(e[i]-0);
        });
        c=Math.floor(temp/10);
        ret=(temp%10)+ret;
    }
    return (c===0?'':c)+ret;
}

natural.subtract=function(a,b){
    if(this.isFormerLarger(b,a)){
        return false;
    }
    var l=b.length;
    var inversedB=b.split('').map(e=>{
        return 9-e;
    }).join('');
    while(inversedB[0]==='0'){
        inversedB=inversedB.slice(1);
    }
    var ret=natural.add(a,inversedB,'1').split('');
    for(var i=ret.length-l-1;i>=0;i--){
        if(ret[i]==='0'){
            ret[i]='9';
        }else{
            ret[i]=(ret[i]-1)+'';
            break;
        }
    }
    while(ret[0]==='0'){
        ret.shift();
    }
    return ret.join('')||'0';
}

natural.isFormerLarger=function(a,b){
    if(a.length>b.length){
        return true;
    }else if(a.length<b.length){
        return false;
    }
    for(var i=0;i<a.length;i++){
        if(a[i]>b[i]){
            return true;
        }else if(a[i]<b[i]){
            return false;
        }
    }
    return false;
}



natural.product=function(...nums){//あまりにも多いnumsは扱えません
    if(nums.some(e=>{return e==='0';})){
        return '0';
    }
    var pointer=new Array(nums.length);
    pointer.fill(0);
    var zeros=0;
    var array=[];
    var str;
    loop1:
    while(true){
        str=1;
        for(var i=0;i<nums.length;i++){
            str*=nums[i][nums[i].length-1-pointer[i]];
        }
        if(str!==0){
            str+='0'.repeat(zeros);
            array.push(str);
        }
        for(var i=0;i<pointer.length;i++){
            if(pointer[i]===nums[i].length-1){
                pointer[i]=0;
                zeros-=nums[i].length-1;
            }else{
                pointer[i]++;
                zeros++;
                break;
            }
            if(i===pointer.length-1){
                break loop1;
            }
        }
    }
    return natural.add(...array);
}

natural.divide=function(a,b){
    if(b==='0'){
        return false;
    }
    if(this.isFormerLarger(b,a)){
        return '0';
    }
    var workbench='';
    var vault=a+'';
    var ret='';
    do{
        workbench+=vault[0];
        vault=vault.slice(1);
        if(workbench==='0'){
            ret+='0';
            workbench='';
            continue;
        }
        for(var i=1;i<=10;i++){
            if(natural.isFormerLarger(natural.product(b,i+''),workbench)){
                if(i>1){
                    workbench=natural.subtract(workbench,natural.product((i-1)+'',b));
                }
                ret+=(i-1)+'';
                break;
            }else if(natural.product(b,i+'')===workbench){
                workbench='';
                ret+=i+'';
                break;
            }
        }
    }while(vault.length>0)
    while(ret[0]==='0'){
        ret=ret.slice(1);
    }
    return ret;
}

natural.mod=function(a,b){
    if(b==='0'){
        return false;
    }
    return natural.subtract(a,natural.product(b,natural.divide(a,b)));
}

natural.factorial=function(a){
    var ret='1';
    for(var i=2;i<=a;i++){
        ret=natural.product(ret,i+'');
    }
    return ret;
}


natural.power=function(a,b){
    if(a==='0'&&b==='0'){
        return false;
    }
    if(a==='0'){
        return '0';
    }
    if(b==='0'){
        return '1';
    }
    var array=[];
    var next;
    var flg;
    while(b!=='0'.repeat(b.length)){
        next=''
        flg=0;
        for(var i=0;i<b.length;i++){
            next+=Math.floor(b[i]/2)+flg;
            flg=(b[i]%2)*5;
        }
        array.push(flg===5);
        b=next;
    }
    var memo=[a];
    for(var i=1;i<array.length;i++){
        memo.push(natural.product(memo[memo.length-1],memo[memo.length-1]));
    }
    var elem=memo.filter((e,i)=>{
        return array[i];
    });
    return natural.product(...elem);
}

natural.lcm=function(...nums){
    var temp=nums[0];
    var a,b;
    for(var i=1;i<nums.length;i++){
        a=temp;
        b=nums[i];
        while(true){
            a=natural.mod(a,b);
            if(a==='0'){
                temp=natural.divide(natural.product(temp,nums[i]),b);
                break;
            }
            b=natural.mod(b,a);
            if(b==='0'){
                temp=natural.divide(natural.product(temp,nums[i]),a);
                break;
            }
        }
    }
    return temp;
}

var rational={};

rational.add=function(...nums){

}

function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const A=input[0].split(' ')[0];
  const B=input[0].split(' ')[1];
  const C=input[0].split(' ')[2];
  const D=input[0].split(' ')[3];
  var ret=natural.subtract(B,A);
  ret=natural.add(ret,'1');
  [C,D].forEach(e=>{
    ret=natural.subtract(ret,natural.subtract(natural.divide(B,e),natural.divide(natural.subtract(A,'1'),e)));
  });
  var e=natural.lcm(D,C);
  ret=natural.add(ret,natural.subtract(natural.divide(B,e),natural.divide(natural.subtract(A,'1'),e)));
  console.log(ret);

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));